Part Number Hot Search : 
AOTF7N60 GRM155 5D100 URR80 P4KE47A TC74H BZX55 EMK21
Product Description
Full Text Search
 

To Download H8-23 Datasheet File

  If you can't view the Datasheet, Please click here to try to view without PDF Reader .  
 
 


  Datasheet File OCR Text:
  to all our customers regarding the change of names ment ioned in the document, such as hitachi electric and hitachi xx, to renesas technology corp. the semiconductor operations of mitsubishi electric and hitachi were transferred to renesas technology corporation on april 1st 2003. these operations include microcomput er, logic, analog and discrete devices, and memory chips other than drams (flash memory, srams etc.) accordingly, although hitachi, hitac hi, ltd., hitachi semiconductors, and other hitachi brand names are m entioned in the document, these names have in fact all been changed to renesas technology corp. thank you for your understanding. ex cept for our corporate trademark, logo and corporate statement, no changes whatsoever have been made to the contents of the document, and these changes do not constitute any alteration to the contents of the document itself. renesas technology home page: www.renesas.com renesas technology corp. customer support dept. april 1, 2003 renesas technology corp.
hitachi single-chip microcomputer h8/325 series h8/3257, h8/3256 h8/325, h8/324, h8/323, h8/322 hardware manual omc 932723275
preface the h8/325 series is a family of high-performance single-chip microcomputers ideally suited for embedded control of industrial equipment. the chips are built around an h8/300 cpu core: a high- speed processor. on-chip supporting modules provide rom, ram, two types of timers, i/o ports, and a serial communication interface for easy implementation of compact, high-speed control systems. the h8/325 series offers a selection of on-chip memory. h8/3257: 60-kbyte rom; 2-kbyte ram h8/3256: 48-kbyte rom; 2-kbyte ram h8/325: 32-kbyte rom; 1-kbyte ram h8/324: 24-kbyte rom; 1-kbyte ram h8/323: 16-kbyte rom; 512-byte ram h8/322: 8-kbyte rom; 256-byte ram the h8/3257, h8/3256, h8/325, h8/323, and h8/322 chips are available with either electrically programmable or mask-programmable rom. manufacturers can use the electrically programmable ztat ? (zero turn-around time*) version to get production off to a fast start and make software changes quickly, then switch over to the masked version for full-scale production runs. this manual describes the h8/325 series hardware. refer to the h8/300 series programming manual for a detailed description of the instruction set. * ztat is a registered trademark of hitachi, ltd.
contents section 1. overview ............................................................................................................... 1 1.1 overview............................................................................................................................... 1 1.2 block diagram...................................................................................................................... 5 1.3 pin assignments and functions............................................................................................ 6 1.3.1 pin arrangement...................................................................................................... 6 1.3.2 pin functions ........................................................................................................... 8 section 2. mcu operating modes and address space ................................................ 15 2.1 overview............................................................................................................................... 15 2.2 mode descriptions................................................................................................................ 16 2.3 address space map .............................................................................................................. 16 2.3.1 access speed ........................................................................................................... 16 2.3.2 ios........................................................................................................................... 17 2.4 mode and system control registers (mdcr and syscr)................................................. 24 2.4.1 mode control register (mdcr) ?h?fc5 ........................................................... 24 2.4.2 system control register (syscr) ?h?fc4 ........................................................ 25 section 3. cpu ........................................................................................................................ 27 3.1 overview............................................................................................................................... 27 3.1.1 features.................................................................................................................... 27 3.2 register configuration.......................................................................................................... 28 3.2.1 general registers..................................................................................................... 28 3.2.2 control registers ..................................................................................................... 29 3.2.3 initial register values.............................................................................................. 30 3.3 addressing modes ................................................................................................................ 31 3.4 data formats......................................................................................................................... 33 3.4.1 data formats in general registers.......................................................................... 34 3.4.2 memory data formats............................................................................................. 35 3.5 instruction set ....................................................................................................................... 36 3.5.1 data transfer instructions ....................................................................................... 38 3.5.2 arithmetic operations ............................................................................................. 40 3.5.3 logic operations ..................................................................................................... 41 3.5.4 shift operations....................................................................................................... 41 3.5.5 bit manipulations .................................................................................................... 43 3.5.6 branching instructions............................................................................................. 49 3.5.7 system control instructions .................................................................................... 51 i
3.5.8 block data transfer instruction .............................................................................. 52 3.6 cpu states ............................................................................................................................ 54 3.6.1 program execution state ......................................................................................... 55 3.6.2 exception-handling state........................................................................................ 55 3.6.3 power-down state ................................................................................................... 56 3.7 access timing and bus cycle .............................................................................................. 56 3.7.1 access to on-chip memory (ram and rom) ...................................................... 56 3.7.2 access to on-chip register field and external devices ........................................ 58 section 4. exception handling ............................................................................................ 61 4.1 overview............................................................................................................................... 61 4.2 reset ..................................................................................................................................... 61 4.2.1 overview ................................................................................................................. 61 4.2.2 reset sequence ........................................................................................................ 61 4.2.3 disabling of interrupts after reset........................................................................... 64 4.3 interrupts............................................................................................................................... 64 4.3.1 overview ................................................................................................................. 64 4.3.2 interrupt-related registers...................................................................................... 65 4.3.3 external interrupts ................................................................................................... 68 4.3.4 internal interrupts .................................................................................................... 69 4.3.5 interrupt handling ................................................................................................... 70 4.3.6 interrupt response time.......................................................................................... 75 4.4 note on stack handling........................................................................................................ 75 section 5. i/o ports ................................................................................................................ 77 5.1 overview............................................................................................................................... 77 5.2 port 1..................................................................................................................................... 78 5.3 port 2..................................................................................................................................... 81 5.4 port 3..................................................................................................................................... 84 5.5 port 4..................................................................................................................................... 87 5.6 port 5..................................................................................................................................... 94 5.7 port 6..................................................................................................................................... 99 5.8 port 7..................................................................................................................................... 104 ii
section 6. parallel handshaking interface ....................................................................... 113 6.1 overview............................................................................................................................... 113 6.1.1 features.................................................................................................................... 113 6.1.2 block diagram......................................................................................................... 114 6.1.3 input and output pins .............................................................................................. 115 6.1.4 register configuration ............................................................................................ 115 6.2 register descriptions............................................................................................................ 115 6.2.1 port 3 data direction register (p3ddr) ................................................................ 115 6.2.2 port 3 data register (p3dr) ................................................................................... 116 6.2.3 handshake control/status register (hcsr)........................................................... 116 6.3 operation .............................................................................................................................. 118 6.3.1 output timing of output strobe signal .................................................................. 118 6.3.2 busy signal output timing ..................................................................................... 119 6.3.3 operation in software standby mode ..................................................................... 119 6.3.4 sample application ................................................................................................. 120 6.3.5 interrupts.................................................................................................................. 121 section 7. 16-bit free-running timer .............................................................................. 123 7.1 overview............................................................................................................................... 123 7.1.1 features.................................................................................................................... 123 7.1.2 block diagram......................................................................................................... 123 7.1.3 input and output pins .............................................................................................. 125 7.1.4 register configuration ............................................................................................ 125 7.2 register descriptions............................................................................................................ 126 7.2.1 free-running counter (frc) ?h?f92 ................................................................. 126 7.2.2 output compare registers a and b (ocra and ocrb) ?h?f94 and h?f96............................................................ 126 7.2.3 input capture register (icr) ?h?f98.................................................................. 127 7.2.4 timer control register (tcr) ?h?f90................................................................ 128 7.2.5 timer control/status register (tcsr) ?h?f91................................................... 130 7.2.6 frt noise canceler control register (fncr) ?h?fff...................................... 133 7.3 cpu interface ....................................................................................................................... 133 7.4 operation .............................................................................................................................. 136 7.4.1 frc incrementation timing.................................................................................... 136 7.4.2 output compare timing.......................................................................................... 138 7.4.3 frc clear timing ................................................................................................... 138 7.4.4 input capture timing .............................................................................................. 139 7.4.5 timing of input capture flag (icf) setting............................................................ 140 iii
7.4.6 setting of frc overflow flag (ovf)..................................................................... 141 7.5 interrupts............................................................................................................................... 142 7.6 noise canceler...................................................................................................................... 142 7.7 sample application............................................................................................................... 144 7.8 application notes ................................................................................................................. 145 section 8. 8-bit timers ......................................................................................................... 151 8.1 overview............................................................................................................................... 151 8.1.1 features.................................................................................................................... 151 8.1.2 block diagram......................................................................................................... 151 8.1.3 input and output pins .............................................................................................. 152 8.1.4 register configuration ............................................................................................ 153 8.2 register descriptions............................................................................................................ 153 8.2.1 timer counter (tcnt) ?h?fc8 (tmr0), h?fd0 (tmr1) .............................. 153 8.2.2 time constant registers a and b (tcora and tcorb) ? h?fca and h?fcb (tmr0), h?fd2 and h?fd3 (tmr1)............................ 154 8.2.3 timer control register (tcr) ?h?fc8 (tmr0), h?fd0 (tmr1) ................... 154 8.2.4 timer control/status register (tcsr) ?h?fc9 (tmr0), h?fd1 (tmr1)...... 156 8.3 operation .............................................................................................................................. 158 8.3.1 tcnt incrementation timing................................................................................. 158 8.3.2 compare match timing........................................................................................... 159 8.3.3 external reset of tcnt .......................................................................................... 161 8.3.4 setting of tcsr overflow flag .............................................................................. 162 8.4 interrupts............................................................................................................................... 163 8.5 sample application............................................................................................................... 163 8.6 application notes ................................................................................................................. 164 section 9. serial communication interface ..................................................................... 169 9.1 overview............................................................................................................................... 169 9.1.1 features.................................................................................................................... 169 9.1.2 block diagram......................................................................................................... 170 9.1.3 input and output pins .............................................................................................. 170 9.1.4 register configuration ............................................................................................ 171 9.2 register descriptions............................................................................................................ 171 9.2.1 receive shift register (rsr) .................................................................................. 171 9.2.2 receive data register (rdr) ?h?fdd ............................................................... 172 9.2.3 transmit shift register (tsr)................................................................................. 172 9.2.4 transmit data register (tdr) ?h?fdb .............................................................. 172 iv
9.2.5 serial mode register (smr) ?h?fd8.................................................................. 173 9.2.6 serial control register (scr) ?h?fda............................................................... 175 9.2.7 serial status register (ssr) ?h?fdc.................................................................. 177 9.2.8 bit rate register (brr) ?h?fd9 ........................................................................ 179 9.3 operation .............................................................................................................................. 183 9.3.1 overview ................................................................................................................. 183 9.3.2 asynchronous mode................................................................................................ 184 9.3.3 synchronous mode .................................................................................................. 188 9.4 interrupts............................................................................................................................... 192 9.5 application notes ................................................................................................................. 193 section 10. ram ....................................................................................................................... 197 10.1 overview............................................................................................................................... 197 10.2 block diagram...................................................................................................................... 197 10.3 ram enable bit (rame) .................................................................................................... 198 10.4 operation .............................................................................................................................. 198 10.4.1 expanded modes (modes 1 and 2) .......................................................................... 198 10.4.2 single-chip mode (mode 3) ................................................................................... 199 section 11. rom ....................................................................................................................... 201 11.1 overview............................................................................................................................... 201 11.1.1 block diagram......................................................................................................... 202 11.2 prom mode......................................................................................................................... 202 11.2.1 prom mode setup ................................................................................................. 202 11.2.2 socket adapter pin assignments and memory map............................................... 203 11.3 programming ........................................................................................................................ 208 11.3.1 selection of sub-modes in prom mode................................................................ 208 11.3.2 writing and verifying .............................................................................................. 209 11.3.3 notes on writing...................................................................................................... 215 11.3.4 reliability of written data ...................................................................................... 215 11.3.5 erasing of data ........................................................................................................ 216 11.4 handling of windowed packages......................................................................................... 216 section 12. power-down state .............................................................................................. 219 12.1 overview............................................................................................................................... 219 12.2 system control register: power-down control bits .......................................................... 220 12.3 sleep mode ........................................................................................................................... 221 12.3.1 transition to sleep mode......................................................................................... 222 v
12.3.2 exit from sleep mode ............................................................................................. 222 12.4 software standby mode........................................................................................................ 222 12.4.1 transition to software standby mode..................................................................... 223 12.4.2 exit from software standby mode.......................................................................... 223 12.4.3 sample application of software standby mode ..................................................... 223 12.4.4 notes on current dissipation .................................................................................. 224 12.5 hardware standby mode ...................................................................................................... 225 12.5.1 transition to hardware standby mode.................................................................... 225 12.5.2 recovery from hardware standby mode................................................................ 226 12.5.3 timing relationships............................................................................................... 226 section 13. e-clock interface ................................................................................................ 227 13.1 overview............................................................................................................................... 227 section 14. clock pulse generator ....................................................................................... 231 14.1 overview............................................................................................................................... 231 14.1.1 block diagram......................................................................................................... 231 14.2 oscillator circuit................................................................................................................... 231 14.3 system clock divider........................................................................................................... 234 section 15. electrical specifications .................................................................................... 235 15.1 absolute maximum ratings ................................................................................................. 235 15.2 electrical characteristics ...................................................................................................... 235 15.2.1 dc characteristics................................................................................................... 235 15.2.2 ac characteristics................................................................................................... 242 15.3 mcu operational timing..................................................................................................... 246 15.3.1 bus timing .............................................................................................................. 246 15.3.2 control signal timing ............................................................................................. 248 15.3.3 16-bit free-running timer timing ........................................................................ 251 15.3.4 8-bit timer timing.................................................................................................. 252 15.3.5 serial communication interface timing ................................................................. 253 15.3.6 i/o port timing........................................................................................................ 254 15.3.7 parallel handshake interface timing ...................................................................... 254 vi
appendices appendix a. cpu instruction set ...................................................................................... 257 a.1 instruction set list................................................................................................................ 257 a.2 operation code map............................................................................................................. 264 a.3 number of states required for execution............................................................................ 266 appendix b. register field ................................................................................................. 272 b.1 register addresses and bit names....................................................................................... 272 b.2 register descriptions............................................................................................................ 276 appendix c. pin states ......................................................................................................... 301 c.1 pin states in each mode ....................................................................................................... 301 appendix d. timing of transition to and recovery from hardware standby mode .................................................................................. 303 appendix e. package dimensions .................................................................................... 304 vii
section 1. overview 1.1 overview the h8/325 series is a series of single-chip microcomputers integrating a cpu core together with a variety of peripheral functions needed in control systems. the h8/300 cpu is a high-speed processor featuring powerful bit-manipulation instructions, ideally suited for realtime control applications. the on-chip supporting modules include rom, ram, two types of timers (16-bit free-running timer and 8-bit timer), a serial communication interface, i/o ports, and a parallel handshaking interface. the on-chip memory sizes of the three chips in the h8/325 series are: h8/3257: 60-kbyte rom; 2-kbyte ram h8/3256: 48-kbyte rom; 2-kbyte ram h8/325: 32-kbyte rom; 1-kbyte ram h8/324: 24-kbyte rom; 1-kbyte ram h8/323: 16-kbyte rom; 512-byte ram h8/322: 8-kbyte rom; 256-byte ram the h8/325 series can operate in single-chip mode or in two expanded modes, depending on the memory requirements of the application. the operating mode is referred to in this manual as the mcu mode (mcu: microcomputer unit). the h8/3257, h8/3256, h8/325, h8/323, and h8/322 are available in a masked rom version, or a ztat* version with electrically programmable rom that can be programmed at the user site. * ztat is a registered trademark of hitachi, ltd. 1
table 1-1 lists the features of the h8/325 series. table 1-1. features feature description cpu general register architecture eight 16-bit general registers, or sixteen 8-bit general registers high speed maximum clock rate: 10 mhz add/subtract: 0.2 s multiply/divide: 1.4 s concise, streamlined instruction set all instructions are 2 or 4 bytes long register-register arithmetic and logic operations register-memory data transfer by mov instruction instruction set features multiply instruction (8 bits 8 bits) divide instruction (16 bits 8 bits) bit-accumulator instructions register-indirect specification of bit positions memory h8/3257 rom: 60 kbytes ram: 2 kbytes h8/3256 rom: 48 kbytes ram: 2 kbytes h8/325 rom: 32 kbytes ram: 1 kbyte h8/324 rom: 24 kbytes ram: 1 kbyte h8/323 rom: 16 kbytes ram: 512 bytes h8/322 rom: 8 kbytes ram: 256 bytes 16-bit free-running one 16-bit free-running counter (also usable for external event counting) timer module two compare outputs (frt: 1 channel) one capture input 8-bit timer module each channel has: (2 channels) one 8-bit up-counter (also usable for external event counting) two time constant registers 2
table 1-1. features (cont.) feature description serial communi- selection of asynchronous and synchronous modes cation interface simultaneous transmit and receive (full duplex operation) (sci: 2 channels) on-chip baud rate generator i/o ports 53 input/output pins (of which 16 can drive large current loads) all input pins have programmable input pull-ups parallel hand- built-in parallel handshaking is available at port 3 shaking interface interrupts four external interrupt pins: nmi, irq 0 to irq 2 seventeen on-chip interrupt sources operating modes mode 1: expanded mode with on-chip rom disabled mode 2: expanded mode with on-chip rom enabled mode 3: single-chip mode power-down sleep mode state software standby mode hardware standby mode other features on-chip clock oscillator e clock output product lineup type code type code (5v series) (3v series) package rom hd6473257c hd6473257vc 64-pin windowed shrink dip prom (dc-64s) hd6473257p hd6473257vp 64-pin shrink dip (dp-64s) hd6473257f hd6473257vf 64-pin qfp (fp-64a) hd6473257cp hd6473257vcp 68-pin plcc (cp-68) hd6433257p hd6433257vp 64-pin shrink dip (dp-64s) masked hd6433257f hd6433257vf 64-pin qfp (fp-64a) rom hd6433257cp hd6433257vcp 68-pin plcc (cp-68) hd6473256p hd6473256vp 64-pin shrink dip (dp-64s) prom hd6473256f hd6473256vf 64-pin qfp (fp-64a) hd6473256cp hd6473256vcp 68-pin plcc (cp-68) hd6433256p hd6433256vp 64-pin shrink dip (dp-64s) masked hd6433256f hd6433256vf 64-pin qfp (fp-64a) rom hd6433256cp hd6433256vcp 68-pin plcc (cp-68) 3
table 1-1. features (cont.) feature description product lineup type code type code (cont.) (5v series) (3v series) package rom hd6473258c 64-pin windowed shrink dip prom (dc-64s) hd6473258p 64-pin shrink dip (dp-64s) hd6473258f 64-pin qfp (fp-64a) hd6473258cp 68-pin plcc (cp-68) hd6433258p 64-pin shrink dip (dp-64s) masked hd6433258f 64-pin qfp (fp-64a) rom hd6433258cp 68-pin plcc (cp-68) hd6413258p 64-pin shrink dip (dp-64s) no hd6413258f 64-pin qfp (fp-64a) rom hd6413258cp 68-pin plcc (cp-68) hd6433248p 64-pin shrink dip (dp-64s) masked hd6433248f 64-pin qfp (fp-64a) rom hd6433248cp 68-pin plcc (cp-68) hd6473238p 64-pin shrink dip (dp-64s) prom hd6473238f 64-pin qfp (fp-64a) hd6473238cp 68-pin plcc (cp-68) hd6433238p 64-pin shrink dip (dp-64s) masked hd6433238f 64-pin qfp (fp-64a) rom hd6433238cp 68-pin plcc (cp-68) hd6413238p 64-pin shrink dip (dp-64s) no hd6413238f 64-pin qfp (fp-64a) rom hd6413238cp 68-pin plcc (cp-68) hd6473228p 64-pin shrink dip (dp-64s) prom hd6473228f 64-pin qfp (fp-64a) hd6473228cp 68-pin plcc (cp-68) hd6433228p 64-pin shrink dip (dp-64s) masked hd6433228f 64-pin qfp (fp-64a) rom hd6433228cp 68-pin plcc (cp-68) 4
1.2 block diagram figure 1-1 shows a block diagram of the h8/325 series. figure 1-1. block diagram rom ram * h8/3257, h8/3256, h8/325, h8/323, and h8/322 are available with prom. h8/322 8 kbytes 256 bytes h8/323 16 kbytes 512 bytes address bus data bus (high) 8-bit timer (2 channels) p7 0 /is p7 1 /os p7 2 /busy p7 3 /ios p7 4 /as p7 5 /wr p7 6 /rd p7 7 /wait p1 0 /a 0 p1 1 /a 1 p1 2 /a 2 p1 3 /a 3 p1 4 /a 4 p1 5 /a 5 p1 6 /a 6 p1 7 /a 7 p2 0 /a 8 p2 1 /a 9 p2 2 /a 10 p2 3 /a 11 p2 4 /a 12 p2 5 /a 13 p2 6 /a 14 p2 7 /a 15 p3 0 /d 0 p3 1 /d 1 p3 2 /d 2 p3 3 /d 3 p3 4 /d 4 p3 5 /d 5 p3 6 /d 6 p3 7 /d 7 xtal extal nmi stby v cc v cc v ss v ss p5 0 /txd 0 p5 1 /rxd 0 p5 2 /sck 0 p5 3 /txd 1 p5 4 /rxd 1 p5 5 /sck 1 p4 0 /tmci 0 p4 1 /tmo 0 p4 2 /tmri 0 p4 3 /tmci 1 p4 4 /tmo 1 p4 5 /tmri 1 p4 6 / p4 7 /e serial communication (2 channels) ram data bus (low) p6 0 /ftci p6 1 /ftoa p6 2 /ftob p6 3 /fti p6 4 /irq 0 p6 5 /irq 1 p6 6 /irq 2 16-bit free-running timer figure 1-1 memory size h8/325 32 kbytes 1 kbyte h8/324 24 kbytes 1 kbyte port 1 port 2 port 3 port 6 port 7 cpu h8/300 clock pulse gener- ator prom* (or masked rom) port 5 port 4 h8/3257 60 kbytes 2 kbytes h8/3256 48 kbytes 2 kbytes 5
1.3 pin assignments and functions 1.3.1 pin arrangement figure 1-2 shows the pin arrangement of the h8/325 series in the dc-64s and dp-64s packages. figure 1-3 shows the pin arrangement in the fp-64a package. figure 1-4 shows the pin arrangement in the cp-68 package. figure 1-2. pin arrangement (dc-64s, dp-64s, top view) 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 p3 /d p3 /d p3 /d p3 /d p3 /d p3 /d p3 /d p3 /d p1 /a p1 /a p1 /a p1 /a p1 /a p1 /a p1 /a p1 /a 7 6 5 4 3 2 1 0 0 1 2 3 4 5 6 7 v p2 /a p2 /a p2 /a p2 /a p2 /a p2 /a p2 /a p2 /a v p7 /wait p7 /rd p7 /wr p7 /as p7 /ios p7 /busy ss 0 1 2 3 4 5 6 7 cc 7 6 5 4 3 2 7 6 5 4 3 2 1 0 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 fig. 1-2 p6 /ftci 0 p6 /ftoa 1 p6 /ftob 2 p6 /fti 3 p6 /irq 4 p6 /irq 5 p6 /irq 6 res xtal md md 1 0 nmi v cc v ss stby extal p4 /tmci 0 0 p4 /tmo 1 0 p4 /tmri 2 0 p4 /tmci 3 1 p4 /tmo 4 1 p4 /tmri 5 1 p4 / 6 p4 /e 7 p5 /txd 0 0 p5 /rxd 1 0 p5 /sck 2 0 p5 /txd 3 1 p5 /rxd 4 1 p5 /sck 5 1 p7 /is 0 p7 /os 1 0 1 2 6
figure 1-3. pin arrangement (fp-64a, top view) p4 /tmo fig. 1-3 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 xtal extal 1 0 cc 0 p1 /a p1 /a p1 /a p1 /a p1 /a p1 /a p1 /a p1 /a v p2 /a p2 /a p2 /a p2 /a p2 /a p2 /a p2 /a 0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 8 9 10 11 12 13 14 ss res p6 /irq p6 /irq p6 /irq p6 /fti p6 /ftob p6 /ftoa p6 /ftci p3 /d p3 /d p3 /d p3 /d p3 /d p3 /d p3 /d p3 /d 6 5 4 3 2 1 0 7 6 5 4 3 2 1 0 2 1 0 p5 /txd p5 /rxd p5 /sck p5 /txd p5 /rxd p5 /sck p7 /is p7 /os p7 /busy p7 /ios p7 /as p7 /wr p7 /rd p7 /wait v p2 /a 0 cc md md nmi v stby ss v p4 /tmci 0 1 0 p4 /tmri 2 0 p4 /tmci 3 1 p4 /tmo 4 1 p4 /tmri 5 1 p4 / 6 p4 /e 7 0 1 0 0 1 1 1 2 3 4 5 0 1 2 3 4 5 6 7 7 15 0 1 2 3 4 5 6 7 7 6 5 4 3 2 1 0 7
? plcc-68 figure 1-4. pin arrangement (cp-68, top view) 1.3.2 pin functions (1) pin assignments in each operating mode: table 1-2 lists the assignments of the pins of the dc-64s, dp-64s, fp-64a, and cp-68 packages in each operating mode. p4 /tmo fig. 1-3 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 45 44 9 8 7 6 5 4 3 2 1 68 67 66 65 64 63 62 61 xtal extal 1 0 cc 0 p1 /a p1 /a p1 /a p1 /a p1 /a p1 /a p1 /a p1 /a v nc p2 /a p2 /a p2 /a p2 /a p2 /a p2 /a p2 /a 0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 8 9 10 11 12 13 14 ss res p6 /irq p6 /irq p6 /irq p6 /fti p6 /ftob p6 /ftoa p6 /ftci nc p3 /d p3 /d p3 /d p3 /d p3 /d p3 /d p3 /d p3 /d 6 5 4 3 2 1 0 7 6 5 4 3 2 1 0 2 1 0 p5 /txd p5 /rxd p5 /sck p5 /txd p5 /rxd p5 /sck p7 /is p7 /os nc p7 /busy p7 /ios p7 /as p7 /wr p7 /rd p7 /wait v p2 /a 0 cc md md nmi v stby ss v p4 /tmci 0 1 0 p4 /tmri 2 0 p4 /tmci 3 1 p4 /tmo 4 1 p4 /tmri 5 1 p4 / 6 p4 /e 7 0 1 0 0 1 1 1 2 3 4 5 0 1 2 3 4 5 6 7 7 15 0 1 2 3 4 5 6 7 7 6 5 4 3 2 1 0 nc 8
table 1-2. pin assignments in each operating mode (1) pin no. dc-64s expanded modes single-chip mode prom dp-64s fp-64a cp-68 mode 1 mode 2 mode 3 mode 1 nc nc nc nc 1 57 2 p6 0 /ftci p6 0 /ftci p6 0 /ftci nc 2 58 3 p6 1 /ftoa p6 1 /ftoa p6 1 /ftoa nc 3 59 4 p6 2 /ftob p6 2 /ftob p6 2 /ftob nc 4 60 5 p6 3 /fti p6 3 /fti p6 3 /fti nc 5 61 6 p6 4 /irq 0 p6 4 /irq 0 p6 4 /irq 0 nc 6 62 7 p6 5 /irq 1 p6 5 /irq 1 p6 5 /irq 1 nc 7 63 8 p6 6 /irq 2 p6 6 /irq 2 p6 6 /irq 2 nc 8 64 9 res res res v pp 9 1 10 xtal xtal xtal nc 10 2 11 extal extal extal nc 11 3 12 md 1 md 1 md 1 v ss 12 4 13 md 0 md 0 md 0 v ss 13 5 14 nmi nmi nmi ea 9 14 6 15 v cc v cc v cc v cc 15 7 16 stby stby stby v ss 16 8 17 v ss v ss v ss v ss 18 nc nc nc nc 17 9 19 p4 0 /tmci 0 p4 0 /tmci 0 p4 0 /tmci 0 eo 0 18 10 20 p4 1 /tmo 0 p4 1 /tmo 0 p4 1 /tmo 0 eo 1 19 11 21 p4 2 /tmri 0 p4 2 /tmri 0 p4 2 /tmri 0 eo 2 20 12 22 p4 3 /tmci 1 p4 3 /tmci 1 p4 3 /tmci 1 eo 3 21 13 23 p4 4 /tmo 1 p4 4 /tmo 1 p4 4 /tmo 1 eo 4 22 14 24 p4 5 /tmri 1 p4 5 /tmri 1 p4 5 /tmri 1 eo 5 23 15 25 p4 6 / eo 6 24 16 26 p4 7 /e p4 7 /e p4 7 eo 7 25 17 27 p5 0 /txd 0 p5 0 /txd 0 p5 0 /txd 0 nc 26 18 28 p5 1 /rxd 0 p5 1 /rxd 0 p5 1 /rxd 0 nc 27 19 29 p5 2 /sck 0 p5 2 /sck 0 p5 2 /sck 0 nc notes: 1. pins marked nc should be left unconnected. 2. the prom mode is a non-operating mode used for programming the on-chip rom. see section 11, rom for details. 9
table 1-2. pin assignments in each operating mode (1) pin no. dc-64s expanded modes single-chip mode prom dp-64s fp-64a cp-68 mode 1 mode 2 mode 3 mode 28 20 30 p5 3 /txd 1 p5 3 /txd 1 p5 3 /txd 1 nc 29 21 31 p5 4 /rxd 1 p5 4 /rxd 1 p5 4 /rxd 1 nc 30 22 32 p5 5 /sck 1 p5 5 /sck 1 p5 5 /sck 1 nc 31 23 33 p7 0 /is p7 0 /is p7 0 /is v cc 32 24 34 p7 1 p7 1 p7 1 /os v cc 35 nc nc nc nc 33 25 36 p7 2 p7 2 p7 2 /busy nc 34 26 37 p7 3 /ios p7 3 /ios p7 3 nc 35 27 38 as as p7 4 nc 36 28 39 wr wr p7 5 nc 37 29 40 rd rd p7 6 nc 38 30 41 wait wait p7 7 nc 39 31 42 v cc v cc v cc v cc 40 32 43 a 15 p2 7 /a 15 p2 7 ce 41 33 44 a 14 p2 6 /a 14 p2 6 ea 14 42 34 45 a 13 p2 5 /a 13 p2 5 ea 13 43 35 46 a 12 p2 4 /a 12 p2 4 ea 12 44 36 47 a 11 p2 3 /a 11 p2 3 ea 11 45 37 48 a 10 p2 2 /a 10 p2 2 ea 10 46 38 49 a 9 p2 1 /a 9 p2 1 oe 47 39 50 a 8 p2 0 /a 8 p2 0 ea 8 51 nc nc nc nc 48 40 52 v ss v ss v ss v ss 49 41 53 a 7 p1 7 /a 7 p1 7 ea 7 50 42 54 a 6 p1 6 /a 6 p1 6 ea 6 51 43 55 a 5 p1 5 /a 5 p1 5 ea 5 52 44 56 a 4 p1 4 /a 4 p1 4 ea 4 53 45 57 a 3 p1 3 /a 3 p1 3 ea 3 54 46 58 a 2 p1 2 /a 2 p1 2 ea 2 notes: 1. pins marked nc should be left unconnected. 2. the prom mode is a non-operating mode used for programming the on-chip rom. see section 11, rom for details. 10
table 1-2. pin assignments in each operating mode (1) pin no. dc-64s expanded modes single-chip mode prom dp-64s fp-64a cp-68 mode 1 mode 2 mode 3 mode 55 47 59 a 1 p1 1 /a 1 p1 1 ea 1 56 48 60 a 0 p1 0 /a 0 p1 0 ea 0 57 49 61 d 0 d 0 p3 0 nc 58 50 62 d 1 d 1 p3 1 nc 59 51 63 d 2 d 2 p3 2 nc 60 52 64 d 3 d 3 p3 3 nc 61 53 65 d 4 d 4 p3 4 nc 62 54 66 d 5 d 5 p3 5 nc 63 55 67 d 6 d 6 p3 6 nc 64 56 68 d 7 d 7 p3 7 nc notes: 1. pins marked nc should be left unconnected. 2. the prom mode is a non-operating mode used for programming the on-chip rom. see section 11, rom for details. 11
(2) pin functions: table 1-3 gives a concise description of the function of each pin. table 1-3. pin functions (1) type symbol i/o name and function power v cc i power: connected to the power supply (+5 v or +3 v). connect both v cc pins to the system power supply (+5 v or +3 v). v ss i ground: connected to ground (0 v). connect both v ss pins to the system power supply (0 v). clock xtal i crystal: connected to a crystal oscillator. the crystal frequency must be double the desired system clock frequency. if an external clock is input at the extal pin, a reverse-phase clock should be input at the xtal pin. extal i external crystal: connected to a crystal oscillator or external clock. the frequency of the external clock must be double the desired system clock frequency. see section 14, clock pulse generator for examples of connections to a crystal and external clock. o system clock: supplies the system clock to peripheral devices. e o enable clock: supplies an e clock to peripheral devices. system res i reset: a low input causes the chip to reset. control stby i standby: a transition to the hardware standby mode (a power-down state) occurs when a low input is received at the stby pin. address a 15 to a 0 o address bus: address output pins. bus data bus d 7 to d 0 i/o data bus: 8-bit bidirectional data bus. bus wait i wait: requests the cpu to insert t w states into the bus cycle control when an off-chip address is accessed. rd o read: goes low to indicate that the cpu is reading an external address. wr o write: goes low to indicate that the cpu is writing to an external address. as o address strobe: goes low to indicate that there is a valid address on the address bus. 12
table 1-3. pin functions (2) type symbol i/o name and function bus ios o i/o select: goes low when the cpu accesses addresses h?f00 to control h?fff in expanded mode. can be used as a chip select signal replacing the upper 8 bits of the address bus when external devices are mapped onto high addresses. interrupt nmi i nonmaskable interrupt: highest-priority interrupt request. signals the nmieg bit in the system control register determines whether the interrupt is requested on the rising or falling edge of the nmi input. irq 0 to i interrupt request 0 to 2: maskable interrupt request pins. irq 2 operating md 1 , i mode: input pins for setting the mcu operating mode mode md 0 according to the table below. control md 1 md 0 mode description 0 1 mode 1 expanded mode with on-chip rom disabled 1 0 mode 2 expanded mode with on-chip rom enabled 1 1 mode 3 single-chip mode the inputs at these pins are latched in mode select bits 1 to 0 (mds1 and mds0) of the mode control register (mdcr) on the rising edge of the res signal. 16-bit free- ftci i frt counter clock input: input pin for an external clock running signal for the free-running timer. timer ftoa, o frt output compare a and b: output pins controlled by ftob comparators a and b of the free-running timer. fti i frt input capture: input capture pin for the free-running timer. 8-bit tmo 0 , o 8-bit timer output (channels 0 and 1): compare-match timer tmo 1 output pins for the 8-bit timers. tmci 0 , i 8-bit timer clock input (channels 0 and 1): tmci 1 external clock input pins for the 8-bit timer counters. tmri 0 , i 8-bit timer reset input (channels 0 and 1): high input tmri 1 at these pins resets the 8-bit timers. 13
table 1-3. pin functions (3) type symbol i/o name and function serial com- txd 0 o serial transmit data (channels 0 and 1): data output munication txd 1 pins for the serial communication interface. interface rxd 0 i serial receive data (channels 0 and 1): data input pins rxd 1 for the serial communication interface. sck 0 i/o serial clock (channels 0 and 1): input/output pins for the sck 1 serial clock signals. general- p1 7 to p1 0 i/o port 1: an 8-bit input/output port with programmable mos purpose input pull-ups and led driving capability. the direction of each i/o bit can be selected in the port 1 data direction register (p1ddr). p2 7 to p2 0 i/o port 2: an 8-bit input/output port with programmable mos input pull-ups and led driving capability. the direction of each bit can be selected in the port 2 data direction register (p2ddr). p3 7 to p3 0 i/o port 3: an 8-bit input/output port with programmable mos input pull-ups. the direction of each bit can be selected in the port 3 data direction register (p3ddr). p4 7 to p4 0 i/o port 4: an 8-bit input/output port with programmable mos input pull-ups. the direction of each bit (except p4 6 ) can be selected in the port 4 data direction register (p4ddr). p5 5 to p5 0 i/o port 5: a 6-bit input/output port with programmable mos input pull-ups. the direction of each bit can be selected in the port 5 data direction register (p5ddr). p6 6 to p6 0 i/o port 6: a 7-bit input/output port with programmable mos input pull-ups. the direction of each bit can be selected in the port 6 data direction register (p6ddr). p7 7 to p7 0 i/o port 7: an 8-bit input/output port with programmable mos input pull-ups. the direction of each bit can be selected in the port 7 data direction register (p7ddr). parallel p3 7 to p3 0 i/o data input/output: data input/output pins for the parallel hand- handshaking interface. shaking is i input strobe: strobe input signal from an external device. interface os o output strobe: strobe output signal to an external device. busy o busy: notifies an external device that the h8/325 series chip is not ready to receive data. 14
section 2. mcu operating modes and address space 2.1 overview the h8/325 series operates in three modes numbered 1, 2, and 3. an additional non-operating mode (mode 0) is used for programming the prom version of the h8/325. the mode is selected by the inputs at the mode pins (md 1 and md 0 ) at the instant when the chip comes out of a reset. as indicated in table 2-1, the mode determines the size of the address space and the usage of on-chip rom and on-chip ram. the romless versions (hd6413258, hd6413238) are used only in mode 1 (expanded mode with on-chip rom disabled). table 2-1. operating modes md 1 md 0 mode address space on-chip rom on-chip ram low low mode 0 low high mode 1 expanded disabled enabled* high low mode 2 expanded enabled enabled* high high mode 3 single-chip enabled enabled * if the rame bit in the system control register (syscr) is cleared to 0, off-chip memory can be accessed instead. modes 1 and 2 are expanded modes that permit access to off-chip memory and peripheral devices. the maximum address space supported by these externally expanded modes is 64 kbytes. in mode 3 (single-chip mode), only on-chip rom and ram and the on-chip register field are used. all ports are available for general-purpose input and output. mode 0 is inoperative in the h8/325 series. avoid setting the mode pins to mode 0. 15
2.2 mode descriptions mode 1 (expanded mode without on-chip rom): mode 1 supports a 64-kbyte address space most of which is off-chip. in particular, the interrupt vector table is located in off-chip memory. the on-chip rom is not used. software can select whether to use the on-chip ram. ports 1, 2, 3 and 7 are used for the address and data bus lines and control signals as follows: ports 1 and 2: address bus port 3: data bus port 7 (partly): bus control signals mode 2 (expanded mode with on-chip rom): mode 2 supports a 64-kbyte address space which includes the on-chip rom. software can select whether or not to use the on-chip ram, and can select the usage of pins in ports 1 and 2. ports 1 and 2: address bus (see note) port 3: data bus port 7 (partly): bus control signals note: in mode 2, ports 1 and 2 are initially general-purpose input ports. software must change the desired pins to output before using them for the address bus. see section 5, i/o ports for details. mode 3 (single-chip mode): in this mode all memory is on-chip. since no off-chip memory is accessed, there is no external address bus. all ports are available for general-purpose input and output. 2.3 address space map figures 2-1 to 2-6 show memory maps of the h8/3257, h8/3256, h8/325, h8/324, h8/323, and h8/322 in each of the three operating modes. the on-chip register field consists of control, status, and data registers for the on-chip supporting modules and i/o ports. off-chip addresses can be accessed only in the expanded modes. access to an off-chip address in the single-chip mode does not cause an address error, but all 1 data are returned. 2.3.1 access speed on-chip rom and ram are accessed a word (16 bits) at a time in two states. (a ?tate?is one system clock cycle.) the on-chip register field is accessed a byte at a time in three states. 16
external memory is accessed a byte at a time in three or more states. the basic bus cycle is three states, but additional wait states can be inserted on request. 2.3.2 ios there are two gaps in the on-chip address space above the on-chip ram. addresses h?f80 to h?f8f, situated between the on-chip ram and register field, are off-chip. addresses h?fa0 to h?faf are also off-chip. these 32 addresses can be conveniently assigned to external i/o devices. to simplify the addressing of devices at these addresses, an ios signal is provided that goes low when the cpu accesses addresses h?f00 to h?fff. the ios signal can be used in place of the upper 8 bits of the address bus. 17
figure 2-1. h8/3257 address space map mode 1 expand mode without on-chip rom h'0000 h'002f h'0030 h'f77f h'ff7f h'ff80 h'ff90 h'ff9f on-chip ram*, 2 kbytes h'f780 on-chip rom, 60 kbytes h'0000 h'002f h'0030 h'efff h'f77f vector table external address space on-chip ram*, 2 kbytes h'f000 h'f780 external address space on-chip rom, 60 kbytes mode 3 single-chip mode h'0000 h'002f h'0030 h'efff h'ff7f vector table on-chip ram, 2 kbytes h'ff90 h'ff9f h'f780 h'ffb0 h'ffff on-chip register field h'ffa0 h'ffaf h'ffb0 h'ffff external address space external address space on-chip register field on-chip register field on-chip register field on-chip register field on-chip register field mode 2 expand mode with on-chip rom h'ff8f h'ff7f h'ff80 h'ff90 h'ff9f h'ffa0 h'ffaf h'ffb0 h'ffff h'ff8f fig. 2-1 external address space external memory can be accessed at these addresses when the rame bit in the system control register (syscr) is cleared to 0. * vector table external address space 18
figure 2-2. h8/3256 address space map mode 1 expand mode without on-chip rom h'0000 h'002f h'0030 h'f77f h'ff7f h'ff80 h'ff90 h'ff9f vector table external address space on-chip ram*, 2 kbytes h'f780 external address space on-chip rom, 48 kbytes h'0000 h'002f h'0030 h'bfff h'f77f vector table external address space on-chip ram*, 2 kbytes h'c000 h'f780 external address space on-chip rom, 48 kbytes mode 3 single-chip mode h'0000 h'002f h'0030 h'bfff h'ff7f vector table on-chip ram, 2 kbytes h'ff90 h'ff9f h'f780 h'ffb0 h'ffff on-chip register field h'ffa0 h'ffaf h'ffb0 h'ffff external address space external address space on-chip register field on-chip register field on-chip register field on-chip register field on-chip register field mode 2 expand mode with on-chip rom h'ff8f h'ff7f h'ff80 h'ff90 h'ff9f h'ffa0 h'ffaf h'ffb0 h'ffff h'ff8f fig. 2-2 external memory can be accessed at these addresses when the rame bit in the system control register (syscr) is cleared to 0. * 19
figure 2-3. h8/325 address space map mode 1 expand mode without on-chip rom h'0000 h'002f h'0030 h'fb7f h'ff7f h'ff80 h'ff90 h'ff9f vector table external address space on-chip ram*, 1 kbyte h'fb80 external address space on-chip rom, 32 kbytes h'0000 h'002f h'0030 h'7fff h'fb7f vector table external address space on-chip ram*, 1 kbyte h'8000 h'fb80 external address space on-chip rom, 32 kbytes mode 3 single-chip mode h'0000 h'002f h'0030 h'7fff h'ff7f vector table on-chip ram, 1 kbyte h'ff90 h'ff9f h'fb80 h'ffb0 h'ffff on-chip register field h'ffa0 h'ffaf h'ffb0 h'ffff external address space external address space on-chip register field on-chip register field on-chip register field on-chip register field on-chip register field mode 2 expand mode with on-chip rom h'ff8f h'ff7f h'ff80 h'ff90 h'ff9f h'ffa0 h'ffaf h'ffb0 h'ffff h'ff8f fig. 2-3 external memory can be accessed at these addresses when the rame bit in the system control register (syscr) is cleared to 0. * 20
figure 2-4. h8/324 address space map mode 1 expand mode without on-chip rom h'0000 h'002f h'0030 h'fb7f h'ff7f h'ff80 h'ff90 h'ff9f vector table external address space on-chip ram, 1 kbyte h'fb80 external address space on-chip rom, 24 kbytes h'0000 h'002f h'0030 h'5fff h'fb7f vector table external address space on-chip ram, 1 kbyte h'6000 h'fb80 external address space on-chip rom, 24 kbytes mode 3 single-chip mode h'0000 h'002f h'0030 h'5fff h'ff7f vector table on-chip ram, 1 kbyte h'ff90 h'ff9f h'fb80 h'ffb0 h'ffff on-chip register field h'ffa0 h'ffaf h'ffb0 h'ffff external address space external address space on-chip register field on-chip register field on-chip register field on-chip register field on-chip register field mode 2 expand mode with on-chip rom h'ff8f h'ff7f h'ff80 h'ff90 h'ff9f h'ffa0 h'ffaf h'ffb0 h'ffff h'ff8f fig. 2-4 *1 *2 this area can be used as external address space when the rame bit of syscr is 0. data read or write is not permitted in these modes. reserved h'7fff h'8000 *1 *1 *2 21
figure 2-5. h8/323 address space map mode 1 expand mode without on-chip rom h'0000 h'002f h'0030 h'fd7f h'ff7f h'ff80 h'ff90 h'ff9f vector table external address space on-chip ram*, 512 bytes h'fd80 external address space on-chip rom, 16 kbytes h'0000 h'002f h'0030 h'3fff h'fd7f vector table external address space on-chip ram*, 512 bytes h'4000 h'fd80 external address space on-chip rom, 16 kbytes mode 3 single-chip mode h'0000 h'002f h'0030 h'3fff h'ff7f vector table on-chip ram, 512 bytes h'ff90 h'ff9f h'fd80 h'ffb0 h'ffff on-chip register field h'ffa0 h'ffaf h'ffb0 h'ffff external address space external address space on-chip register field on-chip register field on-chip register field on-chip register field on-chip register field mode 2 expand mode with on-chip rom h'ff8f h'ff7f h'ff80 h'ff90 h'ff9f h'ffa0 h'ffaf h'ffb0 h'ffff h'ff8f fig. 2-5 * external memory can be accessed at these addresses when the rame bit in the system control register (syscr) is cleared to 0. 22
figure 2-6. h8/322 address space map mode 1 expand mode without on-chip rom h'0000 h'002f h'0030 h'fe7f h'ff7f h'ff80 h'ff90 h'ff9f vector table external address space on-chip ram, 256 bytes h'fe80 external address space on-chip rom, 8 kbytes h'0000 h'002f h'0030 h'fe7f vector table external address space on-chip ram, 256 bytes h'fe80 external address space on-chip rom, 8 kbytes mode 3 single-chip mode h'0000 h'002f h'0030 h'1fff h'ff7f vector table on-chip ram, 256 bytes h'ff90 h'ff9f h'fe80 h'ffb0 h'ffff on-chip register field h'ffa0 h'ffaf h'ffb0 h'ffff external address space external address space on-chip register field on-chip register field on-chip register field on-chip register field on-chip register field mode 2 expand mode with on-chip rom h'ff8f h'ff7f h'ff80 h'ff90 h'ff9f h'ffa0 h'ffaf h'ffb0 h'ffff h'ff8f fig. 2-6 h'1fff h'2000 h'fd7f h'fd80 h'fd7f h'fd80 h'fd80 reserved *1 *2 reserved *1 *2 reserved *2 reserved *2 h'3fff *1 *1 *1 *2 external memory can be accessed at these addresses when the rame bit in the system control register (syscr) is cleared 0. data read or write is not permitted in these modes. 23
2.4 mode and system control registers (mdcr and syscr) two of the control registers in the register field are the mode control register (mdcr) and system control register (syscr). the mode control register controls the mcu mode: the operating mode of the h8/325 series chip. the system control register has a bit that enables or disables the on-chip ram. table 2-2 lists the attributes of these registers. table 2-2. mode and system control registers 2.4.1 mode control register (mdcr)??fc5 bits 7 to 5 and 2?eserved: these bits cannot be modified and are always read as 1. bits 4 and 3?eserved: these bits cannot be modified and are always read as 0. bits 1 and 0?ode select 1 and 0 (mds1 and mds0): these bits indicate the values of the mode pins (md 1 and md 0 ) latched on the rising edge of the res signal. these bits can be read but not written. coding example: to test whether the mcu is operating in mode 1: mov.b @h?fc5, r0l cmp.b #h?5, r0l the comparison is with h?5 instead of h?1 because bits 7, 6, 5, and 2 are always read as 1. name abbreviation read/write address mode control register mdcr r h?fc5 system control register syscr r/w h?fc4 bit 7 6 5 4 3 2 1 0 mds1 mds0 initial value 1 1 1 0 0 1 * * read/write r r r r r r r r * initialized according to md 1 and md 0 inputs. 24
2.4.2 system control register (syscr)??fc4 by setting or clearing bit 0 of the system control register, software can enable or disable the on-chip ram. the other bits in the system control register concern the software standby mode and the valid edge of the nmi signal. these bits will be described in section 4, exception handling and section 12, power-down state. bit 0?am enable (rame): this bit enables or disables the on-chip ram. when the on-chip ram is disabled, accesses to the corresponding addresses are directed off-chip. the rame bit is initialized to 1 by a reset, enabling the on-chip ram. the setting of the rame bit is not altered in the sleep mode or software standby mode. it should be cleared to 0 before entering the hardware standby mode. see section 12, power-down state. coding example: to disable the on-chip ram: bclr #0, @h?fc4 bit 7 6 5 4 3 2 1 0 ssby sts2 sts1 sts0 nmieg rame initial value 0 0 0 0 1 0 1 1 read/write r/w r/w r/w r/w r/w r/w bit 0 rame description 0 the on-chip ram is disabled. 1 the on-chip ram is enabled. (initial state) 25
section 3. cpu 3.1 overview the h8/325 series has the generic h8/300 cpu: an 8-bit central processing unit with a speed- oriented architecture featuring sixteen general registers. this section describes the cpu features and functions, including a concise description of the addressing modes and instruction set. for further details on the instructions, see the h8/300 series programming manual . 3.1.1 features the main features of the h8/300 cpu are listed below. two-way register configuration sixteen 8-bit general registers, or eight 16-bit general registers instruction set with 57 basic instructions, including: multiply and divide instructions powerful bit-manipulation instructions eight addressing modes register direct (rn) register indirect (@rn) register indirect with displacement (@(d:16, rn)) register indirect with post-increment or pre-decrement (@rn+ or @?n) absolute address (@aa:8 or @aa:16) immediate (#xx:8 or #xx:16) pc-relative (@(d:8, pc)) memory indirect (@@aa:8) maximum 64k-byte address space high-speed operation all frequently-used instructions are executed two to four states the maximum clock rate is 10mhz 8- or 16-bit register-register add or subtract: 0.2s 8 8-bit multiply: 1.4s 16 8-bit divide: 1.4s power-down mode sleep instruction 27
3.2 register configuration figure 3-1 shows the register structure of the cpu. there are two groups of registers: the general registers and control registers. figure 3-1. cpu registers 3.2.1 general registers all the general registers can be used as both data registers and address registers. when used as address registers, the general registers are accessed as 16-bit registers (r0 to r7). when used as data registers, they can be accessed as 16-bit registers, or the high and low bytes can be accessed separately as 8-bit registers. r7 also functions as the stack pointer, used implicitly by hardware in processing interrupts and subroutine calls. in assembly-language coding, r7 can also be denoted by the letters sp. as indicated in figure 3-2, r7 (sp) points to the top of the stack. 0 7 r0h r0l r1h r1l r2h r2l r3l r3h r4l r4h r5h r5l r6h r6l r7h r7l (sp) 0 15 pc 0 2 3 5 c v z h 0 7 ccr n i 1 7 sp: stack pointer pc: program counter ccr: condition code register carry flag overflow flag zero flag half-carry flag interrupt mask bit user bit negative flag u u user bit 28
figure 3-2. stack pointer 3.2.2 control registers the cpu control registers include a 16-bit program counter (pc) and an 8-bit condition code register (ccr). (1) program counter (pc): this 16-bit register indicates the address of the next instruction the cpu will execute. each instruction is accessed in 16 bits (1 word), so the least significant bit of the pc is ignored (always regarded as 0). (2) condition code register (ccr): this 8-bit register contains internal status information, including carry (c), overflow (v), zero (z), negative (n), and half-carry (h) flags and the interrupt mask bit (i). bit 7?nterrupt mask bit (i): when this bit is set to ?,?all interrupts except nmi are masked. this bit is set to ??automatically by a reset and at the start of interrupt handling. bit 6?ser bit (u): this bit can be written and read by software for its own purposes. bit 5?alf-carry (h): this bit is set to ??when the add.b, addx.b, sub.b, subx.b, neg.b, or cmp.b instruction causes a carry or borrow out of bit 3, and is cleared to ??otherwise. similarly, it is set to ??when the add.w, sub.w, or cmp.w instruction causes a carry or borrow out of bit 11, and cleared to ??otherwise. it is used implicitly in the daa and das instructions. bit 4?ser bit (u): this bit can be written and read by software for its own purposes. bit 3?egative (n): this bit indicates the most significant bit (sign bit) of the result of an instruction. sp unused area stack area (r7) 29
bit 2?ero (z): this bit is set to ??to indicate a zero result and cleared to ??to indicate a nonzero result. bit 1?verflow (v): this bit is set to ??when an arithmetic overflow occurs, and cleared to ??at other times. bit 0?arry (c): this bit is used by: add and subtract instructions, to indicate a carry or borrow at the most significant bit of the result shift and rotate instructions, to store the value shifted out of the most significant or least significant bit bit manipulation and bit load instructions, as a bit accumulator the ldc, stc, andc, orc, and xorc instructions enable the cpu to load and store the ccr, and to set or clear selected bits by logic operations. some instructions leave some or all of the flag bits unchanged. the action of each instruction on the flag bits is shown in appendix a.1, ?nstruction set list.? see the h8/300 series programming manual for further details. 3.2.3 initial register values when the cpu is reset, the program counter (pc) is loaded from the vector table and the interrupt mask bit (i) in the ccr is set to ?.? the other ccr bits and the general registers are not initialized. in particular, the stack pointer (r7) is not initialized. to prevent program crashes the stack pointer should be initialized by software, by the first instruction executed after a reset. 30
3.3 addressing modes the h8/325 supports eight addressing modes. each instruction uses a subset of these addressing modes. (1) register direct?n: the register field of the instruction specifies an 8- or 16-bit general register containing the operand. in most cases the general register is accessed as an 8-bit register. only the mov.w, add.w, sub.w, cmp.w, adds, subs, mulxu (8 bits 8 bits), and divxu (16 bits 8 bits) instructions have 16-bit operands. (2) register indirect?rn: the register field of the instruction specifies a 16-bit general register containing the address of the operand. (3) register indirect with displacement?(d:16, rn): this mode, which is used only in mov instructions, is similar to register indirect but the instruction has a second word (bytes 3 and 4) which is added to the contents of the specified general register to obtain the operand address. for the mov.w instruction, the resulting address must be even. (4) register indirect with post-increment or pre-decrement?rn+ or @?n: register indirect with post-increment?rn+ the @rn+ mode is used with mov instructions that load registers from memory. it is similar to the register indirect mode, but the 16-bit general register specified in the register field of the instruction is incremented after the operand is accessed. the size of the increment is 1 or 2 depending on the size of the operand: 1 for mov.b; 2 for mov.w. for mov.w, the original contents of the 16-bit general register must be even. register indirect with pre-decrement??n the @?n mode is used with mov instructions that store register contents to memory. it is similar to the register indirect mode, but the 16-bit general register specified in the register field of the instruction is decremented before the operand is accessed. the size of the decrement is 1 or 2 depending on the size of the operand: 1 for mov.b; 2 for mov.w. for mov.w, the original contents of the 16-bit general register must be even. (5) absolute address?aa:8 or @aa:16: the instruction specifies the absolute address of the operand in memory. the mov.b instruction uses an 8-bit absolute address of the form h?fxx. the upper 8 bits are assumed to be 1, so the possible address range is h?f00 to h?fff (65280 to 65535). the mov.b, mov.w, jmp, and jsr instructions can use 16-bit absolute addresses. 31
(6) immediate?xx:8 or #xx:16: the instruction contains an 8-bit operand in its second byte, or a 16-bit operand in its third and fourth bytes. only mov.w instructions can contain 16-bit immediate values. the adds and subs instructions implicitly contain the value 1 or 2 as immediate data. some bit manipulation instructions contain 3-bit immediate data (#xx:3) in the second or fourth byte of the instruction, specifying a bit number. (7) pc-relative?(d:8, pc): this mode is used to generate branch addresses in the bcc and bsr instructions. an 8-bit value in byte 2 of the instruction code is added as a sign-extended value to the program counter contents. the result must be an even number. the possible branching range is ?26 to +128 bytes (?3 to +64 words) from the current address. (8) memory indirect?@aa:8: this mode can be used by the jmp and jsr instructions. the second byte of the instruction code specifies an 8-bit absolute address from h?000 to h?0ff (0 to 255). the word located at this address contains the branch address. note that addresses h?000 to h?03d (0 to 61) are located in the vector table. if an odd address is specified as a branch destination or as the operand address of a mov.w instruction, the least significant bit is regarded as ?,?causing word access to be performed at the address preceding the specified address. see section 3.4.2, ?emory data formats?for further information. 32
3.4 data formats the h8/300 cpu can process 1-bit data, 4-bit (bcd) data, 8-bit (byte) data, and 16-bit (word) data. bit manipulation instructions operate on 1-bit data specified as bit n (n = 0, 1, 2, ..., 7) in a byte operand. all arithmetic and logic instructions except adds and subs can operate on byte data. the daa and das instruction perform decimal arithmetic adjustments on byte data in packed bcd form. each nibble of the byte is treated as a decimal digit. the mov.w, add.w, sub.w, cmp.w, adds, subs, mulxu (8 bits 8 bits), and divxu (16 bits 8 bits) instructions operate on word data. 33
3.4.1 data formats in general registers data of all the sizes above can be stored in general registers as shown in figure 3-3. figure 3-3. register data formats note: rnh: upper digit of general register rnl: lower digit of general register msb: most significant bit lsb: least significant bit 4-bit bcd data 1-bit data 1-bit data byte data byte data word data 4-bit bcd data data type rnl rnh rnl rnh rnl rn rnh register no. don't-care 4 3 7 0 data format 7 0 7 6 5 4 3 2 1 0 don't-care don't-care 7 6 5 4 3 2 1 0 don't-care 7 0 don't-care 7 0 0 15 don't-care 4 3 7 0 7 0 fig. 3-3 m s b l s b m s b l s b m s b l s b upper digit lower digit upper digit lower digit 34
3.4.2 memory data formats figure 3-4 indicates the data formats in memory. word data stored in memory must always begin at an even address. in word access the least significant bit of the address is regarded as ?.? if an odd address is specified, no address error occurs but the access is performed at the preceding even address. this rule affects mov.w instructions and branching instructions, and implies that only even addresses should be stored in the vector table. figure 3-4. memory data formats the stack must always be accessed a word at a time. when the ccr is pushed on the stack, two identical copies of the ccr are pushed to make a complete word. when they are returned, the lower byte is ignored. 7 0 7 6 5 4 3 2 1 0 1-bit data byte data word data byte data (ccr) on stack word data on stack data type data format address address n address n even address odd address even address odd address even address odd address ccr: condition code register * : ignored when return m s b l s b m s b l s b upper 8 bits lower 8 bits m s b l s b m s b l s b ccr ccr * m s b l s b fig. 3-4 35
3.5 instruction set table 3-1 lists the h8/325 series instruction set. table 3-1. instruction classification *1 push rn is equivalent to mov.w rn, @?p. pop rn is equivalent to mov.w @sp+, rn. *2 bcc is a conditional branch instruction in which cc represents a condition code. the following sections give a concise summary of the instructions in each category, and indicate the bit patterns of their object code. the notation used is defined next. function instructions types data transfer mov, movtpe, movfpe, push *1 , pop *1 3 arithmetic operations add, sub, addx, subx, inc, dec, adds, subs, 14 daa, das, mulxu, divxu, cmp, neg logic operations and, or, xor, not 4 shift shal, shar, shll, shlr, rotl, rotr, rotxl, 8 rotxr bit manipulation bset, bclr, bnot, btst, band, biand, bor, 14 bior, bxor, bixor, bld, bild, bst, bist branch bcc *2 , jmp, bsr, jsr, rts 5 system control rte, sleep, ldc, stc, andc, orc, xorc, nop 8 block data transfer eepmov 1 total 57 36
operation notation rd general register (destination) rs general register (source) rn, rm general register r n , r m general register field effective address: general register or memory location (ead) destination operand (eas) source operand sp stack pointer pc program counter ccr condition code register n n (negative) bit of ccr z z (zero) bit of ccr v v (overflow) bit of ccr c c (carry) bit of ccr #imm immediate data #xx:3 3-bit immediate data #xx:8 8-bit immediate data #xx:16 16-bit immediate data op operation field disp displacement abs absolute address b byte w word + addition subtraction multiplication division and logical or logical ? exclusive or logical ? move ? exchange not cc condition field 37
3.5.1 data transfer instructions table 3-2 describes the data transfer instructions. figure 3-5 shows their object code formats. table 3-2. data transfer instructions * size: operand size b: byte w: word instruction size* function mov b/w (eas) ? rd, rs ? (ead) moves data between two general registers or between a general register and memory, or moves immediate data to a general register. the rn, @rn, @(d:16, rn), @aa:16, #xx:8 or #xx:16, @?n, and @rn+ addressing modes are available for byte or word data. the @aa:8 addressing mode is available for byte data only. the @?7 and @r7+ modes require word operands. do not specify byte size for these two modes. movtpe b rs ? (ead) transfers data from a general register to memory in synchronization with the e clock. movfpe b (eas) ? rd transfers data from memory to a general register in synchronization with the e clock. push w rn ? @?p pushes a 16-bit general register onto the stack. equivalent to mov.w rn, @?p. pop w @sp+ ? rn pops a 16-bit general register from the stack. equivalent to mov.w @sp+, rn. 38
figure 3-5. data transfer instruction codes 15 8 7 0 mov r r rm ? rn rn ? @rm, or @rm ? rn @(d:16, rm) ? rn, or disp. rn ? @(d:16, rm) @rm+ ? rn, or rn ? @?m abs. @aa:8 ? rn, or rn ? @aa:8 @aa:16 ? rn, or abs. rn ? @aa:16 r #imm. #xx:8 ? rn #xx:16 ? rn #imm. r movfpe, movtpe movfpe: d = 0 movtpe: d = 1 abs. m n r r m n r n n r n n op op op op op op op op r n op push, pop r r m n r r m n r n op notation op: operation field d: direction field (0?oad from; 1?tore to) r m , r n : register field disp.: displacement abs.: absolute address #imm.: immediate data 39
3.5.2 arithmetic operations table 3-3 describes the arithmetic instructions. see figure 3-6 in section 3.5.4, ?hift operations for their object codes. table 3-3. arithmetic instructions * size: operand size b: byte w: word instruction size* function add b/w rd rs ? rd, rd + #imm ? rd sub performs addition or subtraction on data in two general registers, or addition on immediate data and data in a general register. immediate data cannot be subtracted from data in a general register. word data can be added or subtracted only when both words are in general registers. addx b rd rs c ? rd, rd #imm c ? rd subx performs addition or subtraction with carry or borrow on byte data in two general registers, or addition or subtraction on immediate data and data in a general register. inc b rd #1 ? rd dec increments or decrements a general register. adds w rd #imm ? rd subs adds or subtracts immediate data to or from data in a general register. the immediate data must be 1 or 2. daa b rd decimal adjust ? rd das decimal-adjusts (adjusts to packed bcd) an addition or subtraction result in a general register by referring to the ccr. mulxu b rd rs ? rd performs 8-bit 8-bit unsigned multiplication on data in two general registers, providing a 16-bit result. divxu b rd rs ? rd performs 16-bit 8-bit unsigned division on data in two general registers, providing an 8-bit quotient and 8-bit remainder. cmp b/w rd ?rs, rd ?#imm compares data in a general register with data in another general register or with immediate data. word data can be compared only between two general registers. neg b 0 ?rd ? rd obtains the twos complement (arithmetic complement) of data in a general register. 40
3.5.3 logic operations table 3-4 describes the four instructions that perform logic operations. see figure 3-6 in section 3.5.4, ?hift operations?for their object codes. table 3-4. logic operation instructions 3.5.4 shift operations table 3-5 describes the eight shift instructions. figure 3-6 shows the object code formats of the arithmetic, logic, and shift instructions. table 3-5. shift instructions * size: operand size b: byte instruction size* function and b rd rs ? rd, rd #imm ? rd performs a logical and operation on a general register and another general register or immediate data. or b rd rs ? rd, rd #imm ? rd performs a logical or operation on a general register and another general register or immediate data. xor b rd ? rs ? rd, rd ? #imm ? rd performs a logical exclusive or operation on a general register and another general register or immediate data. not b (rd) ? (rd) obtains the ones complement (logical complement) of general register contents. instruction size* function shal b rd shift ? rd shar performs an arithmetic shift operation on general register contents. shll b rd shift ? rd shlr performs a logical shift operation on general register contents. rotl b rd rotate ? rd rotr rotates general register contents. rotxl b rd rotate through carry ? rd rotxr rotates general register contents through the c (carry) bit. 41
figure 3-6. arithmetic, logic, and shift instruction codes 15 8 7 0 add, sub, cmp addx, subx, mulxu, divxu op adds, subs, inc, dec, daa, das, neg, not op #imm. add, addx, subx, cmp (#xx:8) and, or, xor (rm) #imm. and, or, xor (#xx:8) shal, shar, shll, shlr, rotl, rotr, rotxl, rotxr op op op op r m r n r n r n r m r n r n r n notation op: operation field r m , r n : register field #imm.: immediate data 42
3.5.5 bit manipulations table 3-6 describes the bit-manipulation instructions. figure 3-7 shows their object code formats. table 3-6. bit-manipulation instructions (1) * size: operand size b: byte instruction size* function bset b 1 ? ( of ) sets a specified bit in a general register or memory to ?.? the bit is specified by a bit number, given in 3-bit immediate data or the lower three bits of a general register. bclr b 0 ? ( of ) clears a specified bit in a general register or memory to ?.? the bit is specified by a bit number, given in 3-bit immediate data or the lower three bits of a general register. bnot b ( of ) ? ( of ) inverts a specified bit in a general register or memory. the bit is specified by a bit number, given in 3-bit immediate data or the lower three bits of a general register btst b ( of ) ? z tests a specified bit in a general register or memory and sets or clears the z flag accordingly. the bit is specified by a bit number, given in 3-bit immediate data or the lower three bits of a general register. band b c ( of ) ? c ands the c flag with a specified bit in a general register or memory. biand c [ ( of )] ? c ands the c flag with the inverse of a specified bit in a general register or memory. the bit number is specified by 3-bit immediate data. bor b c ( of ) ? c ors the c flag with a specified bit in a general register or memory. bior c [ ( of )] ? c ors the c flag with the inverse of a specified bit in a general register or memory. the bit number is specified by 3-bit immediate data. bxor b c ? ( of ) ? c xors the c flag with a specified bit in a general register or memory. 43
table 3-6. bit-manipulation instructions (2) * size: operand size b: byte notes on bit manipulation instructions: bset, bclr, bnot, bst, and bist are read-modify- write instructions. they read a byte of data, modify one bit in the byte, then write the byte back. care is required when these instructions are applied to registers with write-only bits and to the i/o port registers. example 1: bclr is executed to clear bit 0 in the port 4 data direction register (p4ddr) under the following conditions. p4 7 : input pin, low, mos pull-up transistor on p4 6 : input pin, high, mos pull-up transistor off p4 5 ?p4 0 : output pins, low the intended purpose of this bclr instruction is to switch p4 0 from output to input. instruction size* function bixor b c ? [( of )] ? c xors the c flag with the inverse of a specified bit in a general register or memory. the bit number is specified by 3-bit immediate data. bld b ( of ) ? c copies a specified bit in a general register or memory to the c flag. bild ( of ) ? c copies the inverse of a specified bit in a general register or memory to the c flag. the bit number is specified by 3-bit immediate data. bst b c ? ( of ) copies the c flag to a specified bit in a general register or memory. bist c ? ( of ) copies the inverse of the c flag to a specified bit in a general register or memory. the bit number is specified by 3-bit immediate data. read read one data byte at the specified address modify modify one bit in the data byte write write the modified data byte back to the specified address 44
before execution of bclr instruction execution of bclr instruction bclr.b #0, @p4ddr ;clear bit 0 in data direction register after execution of bclr instruction explanation: to execute the bclr instruction, the cpu begins by reading p4ddr. since p4ddr is a write-only register, it is read as h'ff, even though its true value is h'3f. next the cpu clears bit 0 of the read data, changing the value to h'fe. finally, the cpu writes this value (h'fe) back to p4ddr to complete the bclr instruction. as a result, p4 0 ddr is cleared to "0," making p4 0 an input pin. in addition, p4 7 ddr and p4 6 ddr are set to "1," making p4 7 and p4 6 output pins. example 2: bset is executed to set bit 0 in the port 4 data register (p4dr) under the following conditions. p4 7 : input pin, low, mos pull-up transistor on p4 6 : input pin, high, mos pull-up transistor off p4 5 ?p4 0 : output pins, low the intended purpose of this bset instruction is to switch the output level at p4 0 from low to high. p4 7 p4 6 p4 5 p4 4 p4 3 p4 2 p4 1 p4 0 input/output input input output output output output output output pin state low high low low low low low low ddr 0 0 1 1 1 1 1 1 dr 1 0 0 0 0 0 0 0 pull-up mos on off off off off off off off p4 7 p4 6 p4 5 p4 4 p4 3 p4 2 p4 1 p4 0 input/output output output output output output output output input pin state low high low low low low low high ddr 1 1 1 1 1 1 1 0 dr 1 0 0 0 0 0 0 0 pull-up mos off off off off off off off off 45
before execution of bset instruction execution of bset instruction bset.b #0, @port4 ;set bit 0 in data register after execution of bset instruction explanation: to execute the bset instruction, the cpu begins by reading port 4. since p4 7 and p4 6 are input pins, the cpu reads the level of these pins directly, not the value in the data register. it reads p4 7 as low ("0") and p4 6 as high ("1"). since p4 5 to p4 0 are output pins, for these pins the cpu reads the value in the data register ("0"). the cpu therefore reads the value of port 4 as h'40, although the actual value in p4dr is h'80. next the cpu sets bit 0 of the read data to "1," changing the value to h'41. finally, the cpu writes this value (h'41) back to p4dr to complete the bset instruction. as a result, bit p4 0 is set to "1," switching pin p4 0 to high output. in addition, bits p4 7 and p4 6 are both modified, changing the on/off settings of the mos pull-up transistors of pins p4 7 and p4 6 . programming solution: the switching of the pull-ups for p4 7 and p4 6 in example 2 can be avoided by reserving a byte in ram as a temporary register for p4dr and using it as follows. ram0 is a symbol for the user-selected address of the temporary register. p4 7 p4 6 p4 5 p4 4 p4 3 p4 2 p4 1 p4 0 input/output input input output output output output output output pin state low high low low low low low low ddr 0 0 1 1 1 1 1 1 dr 1 0 0 0 0 0 0 0 pull-up mos on off off off off off off off p4 7 p4 6 p4 5 p4 4 p4 3 p4 2 p4 1 p4 0 input/output input input output output output output output output pin state low high low low low low low high ddr 0 0 1 1 1 1 1 1 dr 0 1 0 0 0 0 0 1 pull-up off on off off off off off off 46
before execution of bset instruction mov.b #80, r0l ;write data (h'80) for data register mov.b r0l, @ram0 ;write to dr temporary register (ram0) mov.b r0l, @port4 ;write to dr execution of bset instruction bset.b #0, @ram0 ;set bit 0 in dr temporary register (ram0) after execution of bset instruction mov.b @ram0, r0l ;obtain value of temporary register ram0 mov.b r0l, @port4 ;write value to dr p4 7 p4 6 p4 5 p4 4 p4 3 p4 2 p4 1 p4 0 input/output input input output output output output output output pin state low high low low low low low low ddr 0 0 1 1 1 1 1 1 dr 1 0 0 0 0 0 0 0 pull-up mos on off off off off off off off ram0 1 0 0 0 0 0 0 0 p4 7 p4 6 p4 5 p4 4 p4 3 p4 2 p4 1 p4 0 input/output input input output output output output output output pin state low high low low low low low high ddr 0 0 1 1 1 1 1 1 dr 1 0 0 0 0 0 0 1 pull-up mos on off off off off off off off ram0 1 0 0 0 0 0 0 1 47
figure 3-7. bit manipulation instruction codes 15 8 7 0 bset, bclr, bnot, btst #imm. operand: register direct (rn) bit no.: immediate (#xx:3) r n op r 0 0 0 0 operand: register indirect (@rn) #imm. 0 0 0 0 bit no.: immediate (#xx:3) n op op r 0 0 0 0 operand: register indirect (@rn) r 0 0 0 0 bit no.: register direct (rm) m n op op abs. operand: absolute (@aa:8) #imm. 0 0 0 0 bit no.: immediate (#xx:3) op op r 0 0 0 0 operand: register indirect (@rn) #imm. 0 0 0 0 bit no.: immediate (#xx:3) n op op abs. operand: absolute (@aa:8) #imm. 0 0 0 0 bit no.: immediate (#xx:3) op op r 0 0 0 0 operand: register indirect (@rn) #imm. 0 0 0 0 bit no.: immediate (#xx:3) n op op band, bor, bxor, bld, bst #imm. operand: register direct (rn) bit no.: immediate (#xx:3) r n op biand, bior, bixor, bild, bist #imm. operand: register direct (rn) bit no.: immediate (#xx:3) r n op abs. operand: absolute (@aa:8) 0 0 0 0 bit no.: immediate (#xx:3) #imm. op op operand: register direct (rn) bit no.: register direct (rm) op r n r m abs. operand: absolute (@aa:8) 0 0 0 0 bit no.: register direct (rm) op op r m notation op: operation field r m , r n : register field abs.: absolute address #imm.: immediate data 48
3.5.6 branching instructions table 3-7 describes the branching instructions. figure 3-8 shows their object code formats. table 3-7. branching instructions instruction size function bcc branches if condition cc is true. mnemonic cc field description condition bra (bt) 0 0 0 0 always (true) always brn (bf) 0 0 0 1 never (false) never bhi 0 0 1 0 high c z = 0 bls 0 0 1 1 low or same c z = 1 bcc (bhs) 0 1 0 0 carry clear c = 0 (high or same) bcs (blo) 0 1 0 1 carry set (low) c = 1 bne 0 1 1 0 not equal z = 0 beq 0 1 1 1 equal z = 1 bvc 1 0 0 0 overflow clear v = 0 bvs 1 0 0 1 overflow set v = 1 bpl 1 0 1 0 plus n = 0 bmi 1 0 1 1 minus n = 1 bge 1 1 0 0 greater or equal n ? v = 0 blt 1 1 0 1 less than n ? v = 1 bgt 1 1 1 0 greater than z (n ? v) = 0 ble 1 1 1 1 less or equal z (n ? v) = 1 jmp branches unconditionally to a specified address. jsr branches to a subroutine at a specified address. bsr branches to a subroutine at a specified displacement from the current address. rts returns from a subroutine 49
figure 3-8. branching instruction codes 15 8 7 0 cc disp. bcc 0 0 0 0 jmp (@rm) jmp (@aa:16) abs. abs. jmp (@@aa:8) disp. bsr r 0 0 0 0 jsr (@rm) jsr (@aa:16) abs. jsr (@@aa:8) rts m r m op op op op op op op op abs. op notation op: operation field cc: condition field r m : register field disp.: displacement abs.: absolute address 50
3.5.7 system control instructions table 3-8 describes the system control instructions. figure 3-9 shows their object code formats. table 3-8. system control instructions instruction size function rte returns from an exception-handling routine. sleep causes a transition to the power-down state. ldc b rs ? ccr, #imm ? ccr moves immediate data or general register contents to the condition code register. stc b ccr ? rd copies the condition code register to a specified general register. andc b ccr #imm ? ccr logically ands the condition code register with immediate data. orc b ccr #imm ? ccr logically ors the condition code register with immediate data. xorc b ccr ? #imm ? ccr logically exclusive-ors the condition code register with immediate data. nop pc + 2 ? pc only increments the program counter. * size: operand size b: byte 51
figure 3-9. system control instruction codes 3.5.8 block data transfer instruction table 3-9 describes the eepmov instruction. figure 3-10 shows its object code format. table 3-9. block data transfer instruction/eeprom write operation 15 8 7 0 rte, sleep, nop op r ldc, stc (rn) #imm. andc, orc, xorc, ldc (#xx:8) n op op notation op: operation field r n : register field #imm.: immediate data instruction size function eepmov if r4l 0 then repeat @r5+ ? @r6+ r4l ?1 ? r4l until r4l = 0 else next; moves a data block according to parameters set in general registers r4l, r5, and r6. r4l: size of block (bytes) r5: starting source address r6: starting destination address execution of the next instruction starts as soon as the block transfer is completed. 52
figure 3-10. block data transfer instruction/eeprom write operation code notes on eepmov instruction note 1 the eepmov instruction is a block data transfer instruction. it moves the number of bytes specified by r4l from the address specified by r5 to the address specified by r6. when setting r4l and r6, make sure that the final destination address (r6 + r4l) does not exceed h'ffff. the value in r6 must not change from h'ffff to h'0000 during execution of the instruction. note 2 cpu will malfunction after eepmov instruction execution, in the following conditions. eepmov instruction performs block data transfer function. condition when the following conditions are all true: the lsi is set to expanded mode (i.e. mode 1 or mode 2). the destination address of eepmov instruction is external area. at least one wait state is inserted to the last write bus cycle to the destination address by eepmov instruction. 15 8 7 0 op op eeprom r5 ? r5 + r4l ? ? r6 ? r6 + r4l h'ffff not allowed r5 ? r5 + r4l ? ? r6 ? r6 + r4l 53 notation o p : operation field
phenomenon h8/300 cpu will malfunction after eepmov instruction execution. counter measures by software or circuitry please take at least one counter measure from the followings. please use eepmov when the destination is in the internal area (e.g. internal ram). when the destination is the external area, please avoid wait state insertion to the bus cycle. when the case that wait state(s) is required, please substitute eepmov by mov and other instructions as follows: example loop:mov.b @r5+, r4h mov.b r4h, @r6 adds #1, r6 inc r4l bne loop 3.6 cpu states the cpu has three states: the program execution state, exception-handling state, and power-down state. the power-down state is further divided into three modes: the sleep mode, software standby mode, and hardware standby mode. figure 3-11 summarizes these states, and figure 3-12 shows a map of the state transitions. figure 3-11. operating states state program execution state the cpu executes successive program instructions. exception-handling state a transient state triggered by a reset or interrupt. the cpu executes a hardware sequence that includes loading the program counter from the vector table. power-down state sleep mode a state in which some or all of the chip software standby mode functions are stopped to conserve power. hardware standby mode 54
figure 3-12. state transitions 3.6.1 program execution state in this state the cpu executes program instructions in sequence. the main program, subroutines, and interrupt-handling routines are all executed in this state. 3.6.2 exception-handling state the exception-handling state is a transient state that occurs when the cpu is reset or accepts an interrupt. in this state the cpu carries out a hardware-controlled sequence that prepares it to execute a user-coded exception-handling routine. in the hardware exception-handling sequence the cpu does the following: (1) saves the program counter and condition code register to the stack (except in the case of a reset). (2) sets the interrupt mask (i) bit in the condition code register to ?. (3) fetches the start address of the exception-handling routine from the vector table. (4) branches to that address, returning to the program execution state. see section 4, ?xception handling,?for further information on the exception-handling state. reset state hardware standby mode interrupt request res = 1 power-down state sleep mode exception - handling state program execution state interrupt request exception handling sleep instruction with ssby bit set stby=1 or res=0 sleep instruction software standby mode nmi or irq 0 to irq 2 input strobe interrupt notes: 1. a transition to the reset state occurs when res goes low, except when the chip is in the hardware standby mode. 2. a transition from any state to the hardware standby mode occurs when stby goes low. fig. 3-12 55
3.6.3 power-down state the power-down state includes three modes: the sleep mode, the software standby mode, and the hardware standby mode. (1) sleep mode: the sleep mode is entered when a sleep instruction is executed. the cpu halts, but cpu register contents remain unchanged and the on-chip supporting modules continue to function. when an interrupt or reset signal is received, the cpu returns through the exception-handling state to the program execution state. (2) software standby mode: the software standby mode is entered if the sleep instruction is executed while the ssby (software standby) bit in the system control register (syscr) is set. the cpu and all on-chip supporting modules halt. the on-chip supporting modules are initialized, but the contents of the on-chip ram and cpu registers remain unchanged. i/o port outputs also remain unchanged. (3) hardware standby mode: the hardware standby mode is entered when the input at the stby pin goes low. all chip functions halt, including i/o port output. the on-chip supporting modules are initialized, but on-chip ram contents are held. see section 12, ?ower-down state?for further information. 3.7 access timing and bus cycle the cpu is driven by the system clock (). the period from one rising edge of the system clock to the next is referred to as a ?tate. memory access is performed in a two-or three-state bus cycle as described below. for more detailed timing diagrams of the bus cycles, see section 15, ?lectrical specifications. 3.7.1 access to on-chip memory (ram and rom) on-chip rom and ram are accessed in a cycle of two states designated t 1 and t 2 . either byte or word data can be accessed, via a 16-bit data bus. figure 3-13 shows the on-chip memory access cycle. figure 3-14 shows the associated pin states. 56
figure 3-13. on-chip memory access cycle figure 3-14. pin states during on-chip memory access cycle bus cycle t1 state t2 state address read data write data internal address bus internal read signal internal data bus (read) internal write signal internal data bus (write) fig. 3-13 bus cycle t1 state t2 state address address bus as: high rd: high wr: high data bus: high impedance state fig. 3-14 57
3.7.2 access to on-chip register field and external devices the on-chip register field (i/o ports, dual-port ram, on-chip supporting module registers, etc.) and external devices are accessed in a cycle consisting of three states: t 1 , t 2 , and t 3 . only one byte of data can be accessed per cycle, via an 8-bit data bus. access to word data or instruction codes requires two consecutive cycles (six states). wait states: if requested, additional wait states (t w ) are inserted between t 2 and t 3 . the wait pin is sampled at the center of state t 2 . if it is low, a wait state is inserted after t 2 . the wait pin is also sampled at the center of each wait state and if it is still low, another wait state is inserted. an external device can have any number of wait states inserted by holding wait low for the necessary duration. the bus cycle for the movtpe and movfpe instructions will be described in section 15, "e-clock interface." figure 3-15 shows the access cycle for the on-chip register field. figure 3-16 shows the associated pin states. figures 3-17 (a) and (b) show the read and write access timing for external devices. figure 3-15. on-chip register field access cycle bus cycle t1 state t2 state t3 state address read data write data internal address bus internal read signal internal data bus (read) internal write signal internal data bus (write) fig. 3-15 58
figure 3-16. pin states during on-chip register field access cycle figure 3-17 (a). external device access timing (read) bus cycle t1 state t2 state t3 state address address bus as: high rd: high wr: high data bus: high impedance state fig. 3-16 read cycle t1 state t2 state t3 state address read data address bus as rd wr: high data bus fig. 3-17 (a) 59
figure 3-17 (b). external device access timing (write) write cycle t1 state t2 state t3 state address write data address bus as rd: high wr data bus fig. 3-17 (b) 60
section 4. exception handling 4.1 overview the h8/325 series recognizes only two kinds of exceptions: interrupts and the reset. table 4-1 indicates their priority and the timing of their hardware exception-handling sequence. the romless versions (hd6413258, hd6413238) are used only in mode 1 (expanded mode with on-chip rom disabled). table 4-1. reset and interrupt exceptions type of priority exception timing of exception-handling sequence high reset when res goes low, the chip enters the reset state immediately. the hardware exception-handling sequence (reset sequence) begins as soon as res goes high again. interrupt when an interrupt is requested, the hardware exception-handling sequence (interrupt sequence) begins at the end of the current instruction, or at the end of the current hardware exception-handling low sequence. 4.2 reset 4.2.1 overview a reset has the highest exception-handling priority. when the res pin goes low, all current processing stops and the chip enters the reset state. the internal state of the cpu and the registers of the on-chip supporting modules are initialized. when res returns from low to high, the chip comes out of the reset state via the reset exception-handling sequence. 4.2.2 reset sequence the reset state begins when res goes low. to ensure correct resetting, at power-on the res pin should be held low for at least 20ms. in a reset during operation, the res pin should be held low for at least 10 system clock () cycles. when res returns from low to high, hardware carries out the following reset exception-handling sequence. 61
(1) the value at the mode pins (md 1 and md 0 ) is latched in bits mds1 and mds0 of the mode control register (mdcr). (2) in the condition code register (ccr), the i bit is set to 1 to mask interrupts. (3) the registers of the i/o ports and on-chip supporting modules are initialized. (4) the cpu loads the program counter with the first word in the vector table (stored at addresses h?000 and h?001) and starts program execution. the res pin should be held low when power is switched off, as well as when power is switched on. figure 4-1 indicates the timing of the reset sequence when the vector table and reset routine are located in on-chip rom. figure 4-2 indicates the timing when they are in off-chip memory. figure 4-1. reset sequence (mode 2 or 3, reset routine in on-chip rom) (1) (2) (3) res (2) internal address bus internal read signal internal write signal internal data bus (16 bits) (1) reset vector address (h'0000) (2) starting address of reset routine (contents of h'0000?'0001) (3) first instruction of reset routine vector fetch internal processing instruction prefetch figure. 4-1 62
figure 4-2. reset sequence (mode 1) (1) (2) (3) (4) (5) (6) (7) (8) (1),(3) reset vector address: (1)=h'0000, (3)=h'0001 (2),(4) starting address of reset routine (contents of reset vector): (2)=upper byte, (4)=lower byte (5),(7) starting address of reset routine: (5)=(2)(4), (7)=(2)(4)+1 (6),(8) first instruction of reset routine: (6)=first byte, (8)=second byte vector fetch internal process- ing instruction prefetch res d 7 to d 0 (8 bits) a 15 to a 0 rd wr figure. 4-2 63
4.2.3 disabling of interrupts after reset all interrupts, including nmi, are disabled immediately after a reset. the first program instruction, located at the address specified at the top of the vector table, is therefore always executed. to prevent program crashes, this instruction should initialize the stack pointer (example: mov.w #xx:16, sp). after execution of this instruction, the nmi interrupt is enabled. other interrupts remain disabled until their enable bits are set to 1. 4.3 interrupts 4.3.1 overview there are four input pins for external interrupts (nmi, irq 0 to irq 2 ). there are also 17 internal interrupts originating on-chip. the features of these interrupts are: all internal and external interrupts except nmi can be masked by the i bit in the ccr. irq 0 to irq 2 can be rising-edge-sensed, falling-edge-sensed, or level-sensed. the type of sensing can be selected for each interrupt individually. nmi is edge-sensed, and either the rising or falling edge can be selected. interrupts are individually vectored. the software interrupt-handling routine does not have to determine what type of interrupt has occurred. table 4-2 lists all the interrupts in their order of priority and gives their vector numbers and the addresses of their entries in the vector table. 64
table 4-2. interrupts address of entry interrupt source no. in vector table priority nmi 3 h'0006 h'0007 high irq 0 4 h'0008 h'0009 irq 1 5 h'000a h'000b irq 2 6 h'000c h'000d port isi (input strobe) 7 h'000e h'000f 16-bit free- ici (input capture) 8 h'0010 h'0011 running timer ocia (output compare a) 9 h'0012 h'0013 ocib (output compare b) 10 h'0014 h'0015 fovi (overflow) 11 h'0016 h'0017 8-bit timer 0 cmi0a (compare-match a) 12 h'0018 h'0019 cmi0b (compare-match b) 13 h'001a h'001b ovi0 (overflow) 14 h'001c h'001d 8-bit timer 1 cmi1a (compare-match a) 15 h'001e h'001f cmi1b (compare-match b) 16 h'0020 h'0021 ovi1 (overflow) 17 h'0022 h'0023 serial eri0 (receive error) 18 h'0024 h'0025 communication rxi0 (receive end) 19 h'0026 h'0027 interface 0 txi0 (transmit end) 20 h'0028 h'0029 serial eri1 (receive error) 21 h'002a h'002b communication rxi1 (receive end) 22 h'002c h'002d interface 1 txi1 (transmit end) 23 h'002e h'002f low notes: 1. h'0000 and h'0001 contain the reset vector. 2. h'0002 to h'0005 are reserved in the h8/325 series and are not available to the user. 4.3.2 interrupt-related registers the interrupt controller refers to three registers in addition to the ccr. the names and attributes of these registers are listed in table 4-3. 65
table 4-3. registers read by interrupt controller name abbreviation read/write address system control register syscr r/w h?fc4 irq sense control register iscr r/w h?fc6 irq enable register ier r/w h?fc7 (1) system control register (syscr)??fc4 bit 2 (nmieg) is the only bit read by the interrupt controller. bit 2?onmaskable interrupt edge (nmieg): determines whether a nonmaskable interrupt is generated on the falling or rising edge of the nmi input signal. bit 2 nmieg description 0 an interrupt is generated on the falling edge of nmi. (initial state) 1 an interrupt is generated on the rising edge of nmi. see section 10, ram and section 12, power-down state for information on the other syscr bits. (2) irq sense control register (iscr)??fc6 bits 6 and 2?rq 2 sense control (irq 2 sc and irq 2 eg): these bits select how the input at the irq 2 pin is sensed. bit 7 6 5 4 3 2 1 0 ssby sts2 sts1 sts0 nmieg rame initial value 0 0 0 0 1 0 1 1 read/write r/w r/w r/w r/w r/w r/w 66 bit 7 6 5 4 3 2 1 0 irq 2 eg irq 1 eg irq 0 eg irq 2 sc irq 1 sc irq 0 sc initial value 1 0 0 0 1 0 0 0 read/write r/w r/w r/w r/w r/w r/w
bit 2 bit 6 irq 2 sc irq 2 eg description 0 0 the low level of irq 2 generates an interrupt request. (initial state) 0 1 1 0 the falling edge of irq 2 generates an interrupt request. 1 1 the rising edge of irq 2 generates an interrupt request. bits 5 and 1?rq 1 sense control (irq 1 sc and irq 1 eg): these bits select how the input at the irq 1 pin is sensed. bit 1 bit 5 irq 1 sc irq 1 eg description 0 0 the low level of irq 1 generates an interrupt request. (initial state) 0 1 1 0 the falling edge of irq 1 generates an interrupt request. 1 1 the rising edge of irq 1 generates an interrupt request. bits 4 and 0?rq 0 sense control (irq 0 sc and irq 0 eg): these bits select how the input at the irq 0 pin is sensed. bit 0 bit 4 irq 0 sc irq 0 eg description 0 0 the low level of irq 0 generates an interrupt request. (initial state) 0 1 1 0 the falling edge of irq 0 generates an interrupt request. 1 1 the rising edge of irq 0 generates an interrupt request. (3) irq enable register (ier)??fc7 bits 0 to 2?rq 0 to irq 2 enable (irq 0 e to irq 2 e): these bits enable or disable the irq 0 , irq 1 , and irq 2 interrupts individually. bit 7 6 5 4 3 2 1 0 irq 2 e irq 1 e irq 0 e initial value 1 1 1 1 1 0 0 0 read/write r/w r/w r/w 67
bit i (i = 0 to 2) irqie description 0 irqi is disabled. (initial state) 1 irqi is enabled. edge-sensed interrupt signals are latched (if enabled) and held until the interrupt is served. they are latched even if the interrupt mask bit (i) is set in the ccr, and even if bits irq 0 e to irq 2 e are cleared to 0. level-sensed interrupts are not latched. 4.3.3 external interrupts the external interrupts are nmi and irq 0 to irq 2 . while the cpu is waiting for one of these interrupts, it is possible to conserve power by entering software standby mode. when the interrupt arrives, the chip will recover automatically to the program execution state, handle the interrupt, then continue executing the main program. see section 12, power-down state for further information on software standby mode. (1) nmi: a nonmaskable interrupt is generated on the rising or falling edge of the nmi input signal regardless of whether the i (interrupt mask) bit is set in the ccr. the valid edge is selected by the nmieg bit in the system control register. an nmi has highest priority and is always accepted as soon as the current instruction ends, unless the current instruction is an andc, orc, xorc, or ldc instruction. when an nmi interrupt is accepted the interrupt mask (i bit) is set, so the nmi handling routine cannot be interrupted except by another nmi. the nmi vector number is 3. its entry is located at address h?006 in the vector table. (2) irq 0 to irq 2 : these interrupt signals are level-sensed or sensed on the rising or falling edge of the input, as selected by the iscr bits. these interrupts can be masked collectively by the i bit in the ccr, and can be enabled and disabled individually by setting and clearing the bits in the irq enable register. when one of these interrupts is accepted, the i bit is set to 1 to mask further interrupts (except nmi). these interrupts are second in priority to nmi. among them, irq 0 has the highest priority and irq 2 the lowest priority. interrupts irq 0 to irq 2 do not depend on whether pins irq 0 to irq 2 are input or output pins. when using external interrupts irq 0 to irq 2 , clear the corresponding ddr bits to 0 to set these pins to the input state. 68
4.3.4 internal interrupts seventeen internal interrupts can be requested by the on-chip supporting modules. all of them are masked when the i bit in the ccr is set. in addition, they can all be enabled or disabled by bits in the control registers of the on-chip supporting modules. when one of these interrupts is accepted, the i bit is set to 1 to mask further interrupts (except nmi). power can be conserved by waiting for an internal interrupt in sleep mode, in which the cpu halts but the on-chip supporting modules continue to run. when the interrupt arrives, the cpu returns to the program-execution state, services the interrupt, then resumes execution of the main program. see section 12, power-down state for further information on the sleep mode. the input strobe interrupt (isi) can also be waited for in software standby mode. the chip recovers from software standby mode when an input strobe interrupt is requested. the internal interrupt signals received by the interrupt controller are generated from flag bits in the registers of the on-chip supporting modules. the interrupt controller does not reset these flag bits when accepting the interrupt. for the vector numbers and priority order of these interrupts, see table 4-2. note: when disabling internal interrupts, note the following points. 1. set the interrupt mask (i) to 1 before disabling an internal interrupt or clearing its interrupt flag. 2. if an instruction that disables or clears an internal interrupt is executed while the interrupt mask (i) is cleared to 0, and the interrupt is requested during execution of the instruction, the cpu resolves this conflict as follows: if one or more other interrupts are also requested, the other interrupt with the highest priority is served. if no other interrupt is requested, the cpu branches to the reset address. example: a sample program for disabling the output compare a interrupt is shown below. the ociae bit in the tcr should be cleared only when i = 1, as in this example. orc #80, ccr ; set i bit bclr #5, @tcr ; disable output compare a interrupt andc #7f, ccr ; clear i bit 69
note: interrupt requests are not detected immediately after the andc, orc, xorc, and ldc instructions. 4.3.5 interrupt handling figure 4-3 shows a block diagram of the interrupt controller. figure 4-4 is a flowchart showing the operation of the interrupt controller and the sequence by which an interrupt is accepted. this sequence is outlined below. (1) the interrupt controller receives an interrupt request signal. interrupt request signals can be generated by nmi input, or by other interrupt sources if enabled. (2) when notified of an interrupt, the interrupt controller scans the interrupt signals in priority order and selects the one with the highest priority. (see table 4-2 for the priority order.) other requested interrupts remain pending. (3) the interrupt controller accepts the interrupt if it is an nmi, or if it is another interrupt and the i bit in the ccr is cleared to 0. if the interrupt is not an nmi and the i bit is set to 1, the interrupt is held pending. (4) when an interrupt is accepted, after completion of the current instruction, first the pc then the ccr is pushed onto the stack. see figure 4-5. the stacked pc indicates the address of first instruction executed after return from the interrupt-handling routine. (5) the interrupt controller sets the i bit in the ccr to 1, masking all further interrupts except nmi during the interrupt-handling routine. (6) the interrupt controller generates the vector address of the interrupt and loads the word at this address into the program counter. 70
the timing of this sequence is shown in figure 4-6 for the case in which the program and vector table are in on-chip rom and the stack is in on-chip ram. figure 4-3. block diagram of interrupt controller h161 h8/337 h.m '91 fig. 4-3 irq flag 0 irq 0 e adf adie cpu i (ccr) nmi interrupt interrupt controller priority decision irq 0 interrupt interrupt request vector number adi interrupt 71
figure 4-4. hardware interrupt-handling sequence program execution interrupt request present? i=0 in ccr? pending save pc save ccr i 1, masking all interrupts except nmi nmi ? y n y y y y y n n irq 0 ? n n pc: program counter ccr: condition code register i: interrupt mask bit irq 1 ? to software interrupt-handling routine figure. 4-4 txi 1 ? 72
figure 4-5. usage of stack in interrupt handling sp(r7) sp-4 sp-3 sp-2 sp-1 sp(r7) stack area sp+1 sp+2 sp+3 sp+4 even address ccr ccr * pc (upper byte) pc (lower byte) before interrupt is accepted after interrupt is accepted pushed onto stack program counter condition code register stack pointer pc ccr sp : : : 1. 2. the pc contains the address of the first instruction executed after return. registers must be saved and restored by word access at an even address. notes: * ignored on return. : figure. 4-5 73
figure 4-6. timing of interrupt sequence (3) (5) (6) (8) (9) (1) interrupt priority decision. wait for end of instruction. interrupt accepted internal process- ing stack vector table fetch internal process- ing instruction fetch (first instruction of interrupt-handling routine) interrupt request signal internal address bus internal write signal internal read signal internal 16-bit data bus (1) instruction prefetch address (pushed on stack. instruction is executed on return from interrupt-handling routine.) (2) (4) instruction code (not executed) (3) instruction prefetch address (not executed) (5) sp? (6) sp? (7) ccr (8) address of vector table entry (9) vector table entry (address of first instruction interrupt-handling routine) (10) first instruction of interrupt-handling routine (1) (2) (4) (7) (9) (10) instruction fetch figure. 4-6 74 (1) instruction prefetch address (pushed on stack. instruction is executed on return from interrupt-handling routine.) (2) (4) instruction code (not executed) (3) instruction prefetch address (not executed) (5) sp? (6) sp? (7) ccr (8) address of vector table entry (9) vector table entry (address of first instruction interrupt-handling routine) (10) first instruction of interrupt-handling routine
4.3.6 interrupt response time table 4-4 indicates the time that elapses from an interrupt request signal until the first instruction of the software interrupt-handling routine is executed. since the h8/325 series accesses its on-chip memory 16 bits at a time, very fast interrupt service can be obtained by placing interrupt-handling routines in on-chip rom and the stack in on-chip ram. table 4-4. number of states before interrupt service number of states no. reason for wait on-chip memory external memory 1 interrupt priority decision 2 *3 2 *3 2 wait for completion of 1 to 13 5 to 17 *2 current instruction *1 3 save pc and ccr 4 12 *2 4 fetch vector 2 6 *2 5 fetch instruction 4 12 *2 6 internal processing 4 4 total 17 to 29 41 to 53 *2 notes: 1. these values do not apply if the current instruction is an eepmov, movfpe, or movtpe instruction. 2. if wait states are inserted in external memory access, these values may be longer. 3. 1 for internal interrupts. 4.4 note on stack handling in word access, the least significant bit of the address is always assumed to be 0. the stack is always accessed by word access. care should be taken to keep an even value in the stack pointer (general register r7). use the push and pop (or mov.w rn, @?p and mov.w @sp+, rn) instructions to push and pop registers on the stack. setting the stack pointer to an odd value can cause programs to crash. figure 4-7 shows an example of damage caused when the stack pointer contains an odd address. 75
figure 4-7. example of damage caused by setting an odd address in r7 although the ccr consists of only one byte, it is treated as word data when pushed on the stack. in the hardware interrupt exception-handling sequence, two identical ccr bytes are pushed onto the stack to make a complete word. when popped from the stack by an rte instruction, the ccr is loaded from the byte stored at the even address. the byte stored at the odd address is ignored. pc h r1 l sp sp sp pc l pc l h'fefd h'feff h'fefc bsr instruction mov.b r1l, @?7 pc is improperly stored beyond top of stack h'feff set in sp pc is lost h pc h : upper byte of program counter lower byte of program counter general register stack pointer pc l : r1 l : sp : figure. 4-7 76
section 5. i/o ports 5.1 overview the h8/325 series has seven parallel i/o ports, including: five 8-bit input/output ports?orts 1, 2, 3, 4, and 7 one 7-bit input/output port?ort 6 one 6-bit input/output port?ort 5 all ports have programmable mos input pull-ups. ports 1 and 2 can drive leds. input and output are memory-mapped. the cpu views each port as a data register (dr) located in the register field at the high end of the address space. each port also has a data direction register (ddr) which determines which pins are used for input and which for output. output: to send data to an output port, the cpu selects output in the data direction register and writes the desired data in the data register, causing the data to be held in a latch. the latch output drives the pin through a buffer amplifier. if the cpu reads the data register of an output port, it obtains the data held in the latch rather than the actual level of the pin. input: to read data from an i/o port, the cpu selects input in the data direction register and reads the data register. this causes the input logic level at the pin to be placed directly on the internal data bus. there is no intervening input latch, except for port 3 when parallel handshaking is used. mos pull-up: the mos pull-ups for input pins are controlled as follows. to turn on the pull-up transistor for a pin, software must first clear its data direction bit to 0 to make the pin an input pin, then write a 1 in the data bit for that pin. the pull-up can be turned off by writing a 0 in the data bit, or a 1 in the data direction bit. the pull-ups are also turned off by a reset and by entry to the hardware standby mode. the data direction registers are write-only registers; their contents are invisible to the cpu. if the cpu reads a data direction register all bits are read as 1, regardless of their true values. care is required if bit manipulation instructions are used to set and clear the data direction bits. see the note on bit manipulation instructions in section 3.5.5, bit manipulations. auxiliary functions: in addition to their general-purpose input/output functions, all of the i/o ports have auxiliary functions. most of the auxiliary functions are software-selectable and must be enabled by setting bits in control registers. when selected, an auxiliary function usually replaces the general-purpose input/output function, but in some cases both functions operate simultaneously. table 5-1 summarizes the auxiliary functions of the ports. 77
table 5-1. auxiliary functions of input/output ports notes: *1 selected automatically in mode 1; software-selectable in mode 2 *2 data bus function is selected automatically in modes 1 and 2 5.2 port 1 port 1 is an 8-bit input/output port that also provides the low bits of the address bus. the function of port 1 depends on the mcu mode as indicated in table 5-2. table 5-2. functions of port 1 * depending on the bit settings in the data direction register: 0?nput pin; 1?ddress pin pins of port 1 can drive a single ttl load and a 90-pf capacitive load when they are used as output pins. they can also drive light-emitting diodes or a darlington pair. i/o port auxiliary functions port 1 address bus (low) (note 1) port 2 address bus (high) (note 1) port 3 data bus or parallel handshaking data lines (note 2) port 4 system clock and e clock output, 8-bit timer input and output port 5 serial communication interface port 6 free-running timer input and output, irq 2 to irq 0 port 7 bus control and parallel handshaking control mode 1 mode 2 mode 3 address bus (low) input port or input/output port (a 7 to a 0 ) address bus (low) (a 7 to a 0 )* 78
table 5-3 details the port 1 registers. table 5-3. port 1 registers port 1 data direction register (p1ddr)??fb0 p1ddr is an 8-bit register that selects the direction of each pin in port 1. a pin functions as an output pin if the corresponding bit in p1ddr is set to 1, and as an input pin if the bit is cleared to 0. port 1 data register (p1dr)??fb2 p1dr is an 8-bit register containing output data for pins p1 7 to p1 0 , and controlling their input pull- ups. mos pull-ups: are available for input pins in modes 2 and 3. software can turn on the mos pull- up by writing a 1 in p1dr, and turn it off by writing a 0. the pull-ups are automatically turned off for output pins in modes 2 and 3, and for all pins in mode 1. mode 1: in mode 1 (expanded mode without on-chip rom), port 1 is automatically used for address output. the port 1 data direction register is unwritable. all bits in p1ddr are automatically set to 1 and cannot be cleared to 0. name abbreviation read/write initial value address port 1 data direction register p1ddr w h?f (mode 1) h?fb0 h?0 (modes 2 and 3) port 1 data register p1dr r/w h?0 h?fb2 bit 7 6 5 4 3 2 1 0 p1 7 ddr p1 6 ddr p1 5 ddr p1 4 ddr p1 3 ddr p1 2 ddr p1 1 ddr p1 0 ddr mode 1 initial value 1 1 1 1 1 1 1 1 read/write modes 2 and 3 initial value 0 0 0 0 0 0 0 0 read/write w w w w w w w w bit 7 6 5 4 3 2 1 0 p1 7 p1 6 p1 5 p1 4 p1 3 p1 2 p1 1 p1 0 initial value 0 0 0 0 0 0 0 0 read/write r/w r/w r/w r/w r/w r/w r/w r/w 79
mode 2: in mode 2 (expanded mode with on-chip rom), the usage of port 1 can be selected on a pin-by-pin basis. a pin is used for general-purpose input if its data direction bit is cleared to 0, or for address output if its data direction bit is set to 1. mode 3: in the single-chip mode port 1 is a general-purpose input/output port. reset: a reset clears p1ddr and p1dr to all 0, placing all pins in the input state with the mos pull-ups off. in mode 1, when the chip comes out of reset p1ddr is set to all 1, making all pins address output pins. hardware standby mode: all pins are placed in the high-impedance state with the mos pull-ups off. software standby mode: p1ddr and p1dr remain in their previous state. address output pins are low. general-purpose output pins continue to output the data in p1dr. the mos pull-ups of input pins are on or off depending on the values in p1dr. figure 5-1 shows a schematic diagram of port 1. 80
figure 5-1. port 1 schematic diagram 5.3 port 2 port 2 is an 8-bit input/output port that also provides the high bits of the address bus. the function of port 2 depends on the mcu mode as indicated in table 5-4. table 5-4. functions of port 2 * depending on the bit settings in the data direction register: 0?nput pin; 1?ddress pin p1 n r q d c r q d c internal data bus internal lower address bus hardware standby mode 3 mode 1 or 2 reset wp1 mode 1 reset s wp1d p1 n ddr p1 n dr rp1 wp1d: write port 1 ddr wp1: write port 1 rp1: read port 1 n =0 to7 * set-priority * figure 5-1 mode 1 mode 2 mode 3 address bus (high) input port or input/output port (a 15 to a 8 ) address bus (high) (a 15 to a 8 )* 81
pins of port 2 can drive a single ttl load and a 90-pf capacitive load when they are used as output pins. they can also drive light-emitting diodes or a darlington pair. table 5-5 details the port 2 registers. table 5-5. port 2 registers port 2 data direction register (p2ddr)??fb1 p2ddr is an 8-bit register that selects the direction of each pin in port 2. a pin functions as an output pin if the corresponding bit in p2ddr is set to 1, and as an input pin if the bit is cleared to 0. port 2 data register (p2dr)??fb3 p2dr is an 8-bit register containing output data for pins p2 7 to p2 0 , and controlling their input pull- ups. mos pull-ups: are available for input pins in modes 2 and 3. software can turn on the mos pull- up by writing a 1 in p2dr, and turn it off by writing a 0. the pull-ups are automatically turned off for output pins in modes 2 and 3, and for all pins in mode 1. name abbreviation read/write initial value address port 2 data direction register p2ddr w h?f (mode 1) h?fb1 h?0 (modes 2 and 3) port 2 data register p2dr r/w h?0 h?fb3 bit 7 6 5 4 3 2 1 0 p2 7 p2 6 p2 5 p2 4 p2 3 p2 2 p2 1 p2 0 initial value 0 0 0 0 0 0 0 0 read/write r/w r/w r/w r/w r/w r/w r/w r/w bit 7 6 5 4 3 2 1 0 p2 7 ddr p2 6 ddr p2 5 ddr p2 4 ddr p2 3 ddr p2 2 ddr p2 1 ddr p2 0 ddr mode 1 initial value 1 1 1 1 1 1 1 1 read/write modes 2 and 3 initial value 0 0 0 0 0 0 0 0 read/write w w w w w w w w 82
mode 1: in mode 1 (expanded mode without on-chip rom), port 2 is automatically used for address output. the port 2 data direction register is unwritable. all bits in p2ddr are automatically set to 1 and cannot be cleared to 0. mode 2: in mode 2 (expanded mode with on-chip rom), the usage of port 2 can be selected on a pin-by-pin basis. a pin is used for general-purpose input if its data direction bit is cleared to 0, or for address output if its data direction bit is set to 1. mode 3: in single-chip mode port 2 is a general-purpose input/output port. reset: a reset clears p2ddr and p2dr to all 0, placing all pins in the input state with the mos pull-ups off. in mode 1, when the chip comes out of reset p2ddr is set to all 1, making all pins address output pins. hardware standby mode: all pins are placed in the high-impedance state with the mos pull-ups off. software standby mode: p2ddr and p2dr remain in their previous state. address output pins are low. general-purpose output pins continue to output the data in p2dr. the mos pull-ups of input pins are on or off depending on the values in p2dr. figure 5-2 shows a schematic diagram of port 2. 83
figure 5-2. port 2 schematic diagram 5.4 port 3 port 3 is an 8-bit input/output port that also provides the external data bus and data pins for the parallel handshaking interface. the function of port 3 depends on the mcu mode as indicated in table 5-6. for further information on parallel handshaking, see section 6, parallel handshaking interface. table 5-6. functions of port 3 pins of port 3 can drive a single ttl load and a 90-pf capacitive load when they are used as output internal data bus p2 n r q d c r q d c internal address bus hardware standby mode 3 mode 1 or 2 reset wp2 mode 1 reset s wp2d p2 n ddr p2 n dr rp2 wp2d: write port 2 ddr wp2: write port 2 rp2: read port 2 n = 0 to7 * set-priority * figure 5-2 mode 1 mode 2 mode 3 data bus data bus general-purpose input/output port or parallel handshaking port 84
pins. they can also drive a darlington pair. table 5-7 details the port 3 registers. table 5-7. port 3 registers port 3 data direction register (p3ddr)??fb4 p3ddr is an 8-bit register that selects the direction of each pin in port 3. a pin functions as an output pin if the corresponding bit in p3ddr is set to 1, and as an input pin if the bit is cleared to 0. port 3 data register (p3dr)??fb6 p3dr is an 8-bit register containing output data for pins p3 7 to p3 0 in mode 3, and controlling their input pull-ups. mos pull-ups: are available for input pins in mode 3. software can turn on the mos pull-up by writing a 1 in p3dr, and turn it off by writing a 0. the pull-ups are automatically turned off for output pins in mode 3, and for all pins in modes 1 and 2. modes 1 and 2: in the expanded modes, port 3 is automatically used as the data bus. the values in p3ddr and p3dr are ignored. mode 3: in the single-chip mode, port 3 can be used as a general-purpose input/output port, or a parallel-handshaking input or output port. name abbreviation read/write initial value address port 3 data direction register p3ddr w h?f h?fb4 port 3 data register p3dr r/w h?0 h?fb6 bit 7 6 5 4 3 2 1 0 p3 7 ddr p3 6 ddr p3 5 ddr p3 4 ddr p3 3 ddr p3 2 ddr p3 1 ddr p3 0 ddr initial value 0 0 0 0 0 0 0 0 read/write w w w w w w w w bit 7 6 5 4 3 2 1 0 p3 7 p3 6 p3 5 p3 4 p3 3 p3 2 p3 1 p3 0 initial value 0 0 0 0 0 0 0 0 read/write r/w r/w r/w r/w r/w r/w r/w r/w 85
input latches: all pins of port 3 have input latches which can be enabled by the lte bit in the handshake control/status register (hcsr) in mode 3. when the lte bit is set to 1, input data are latched on the falling edge of the input strobe (is) signal and held in the input strobe latch until read. when the lte bit is cleared to 0, input data are passed through the input strobe latch without being held. see section 6, parallel handshaking interface for further information. reset and hardware standby mode: p3ddr and p3dr are cleared to all 0, and all parallel handshaking functions are disabled. all pins are placed in the input (high-impedance) state with the mos pull-ups off. software standby mode: p3ddr and p3dr remain in their previous state. in modes 1 and 2, all pins are placed in the input (high-impedance) state. in mode 3, all pins remain in their previous input or output state. figure 5-3 shows a schematic diagram of port 3. 86
figure 5-3. port 3 schematic diagram 5.5 port 4 port 4 is an 8-bit input/output port that also provides input and output pins for the 8-bit timers and output pins for the system clock and e clock. the pin functions depend on the mcu mode and output select bits in the timer control/status registers. table 5-8 lists the pin functions. p3 n internal data bus mode 3 mode 1 or 2 rp3 external address write external address read wp3d: write port 3 ddr wp3: write port 3 rp3: read port 3 n = 0 to 7 r q d c reset wp3d p3 n ddr r q d c reset wp3 p3 n dr figure 5-3 r d q c reset input latch mode 3 mode 3 control logic is input 87
table 5-8. port 4 pin functions see section 8, 8-bit timer module for details of the timer output select bits. pins of port 4 can drive a single ttl load and a 90-pf capacitive load when they are used as output pins. they can also drive a darlington pair. table 5-9 details the port 4 registers. table 5-9. port 4 registers port 4 data direction register (p4ddr)??fb5 p4ddr is an 8-bit register that selects the direction of each pin in port 4. a pin functions as an output pin if the corresponding bit in p4ddr is set to 1, and as an input pin if the bit is cleared to 0. usage pin functions i/o port p4 0 p4 1 p4 2 p4 3 p4 4 p4 5 p4 6 p4 7 timer or clock tmci 0 tmo 0 tmri 0 tmci 1 tmo 1 tmri 1 clock e clock name abbreviation read/write initial value address port 4 data direction register p4ddr w h?0 (modes 1 and 2) h?fb5 h'00 (mode 3) port 4 data register p4dr r/w h?0 h?fb7 bit 7 6 5 4 3 2 1 0 p4 7 ddr p4 6 ddr p4 5 ddr p4 4 ddr p4 3 ddr p4 2 ddr p4 1 ddr p4 0 ddr modes 1 and 2 initial value 1 0 0 0 0 0 0 0 read/write w w w w w w w w mode 3 initial value 0 0 0 0 0 0 0 0 read/write w w w w w w w w 88
port 4 data register (p4dr)??fb7 p4dr is an 8-bit register containing output data for pins p4 7 to p4 0 , and controlling their input pull- ups. when the cpu reads p4dr, for output pins (p4ddr = 1) it reads the value in the p4dr latch, but for input pins (p4ddr = 0), it obtains the logic level directly from the pin, bypassing the p4dr latch. this also applies to pins used for timer or clock input or output. mos pull-ups: are available for input pins, including timer input pins, in all modes. software can turn the mos pull-up on by writing a 1 in p4dr, and turn it off by writing a 0. the pull-ups are automatically turned off for output pins. pins p4 0 , p4 2 , p4 3 , and p4 5 : as indicated in table 5-8, these pins can be used for general-purpose input or output, or input of 8-bit timer clock and reset signals. when a pin is used for timer signal input, its p4ddr bit should normally be cleared to 0; otherwise the timer will receive the value in p4dr. if input pull-up is not desired, the p4dr bit should also be cleared to 0. pins p4 1 and p4 4 : as indicated in table 5-8, these pins can be used for general-purpose input or output, or for 8-bit timer output. pins used for timer output are unaffected by the values in p4ddr and p4dr, and their mos pull-ups are automatically turned off. pin p4 6 : in modes 1 and 2 (expanded modes) this pin is used for system clock () output, regardless of the value in p4 6 ddr. the mos pull-up is automatically turned off. in mode 3 (single-chip mode) this pin is used for general-purpose input if p4 6 ddr is cleared to 0, or system clock output if p4 6 ddr is set to 1. it cannot be used for general-purpose output. pin p4 7 : in modes 1 and 2 (expanded modes) pin p4 7 is used for e clock output if p4 7 ddr is set to 1, and for general-purpose input if p4 7 ddr is cleared to 0. it cannot be used for general-purpose output. in mode 3 (single-chip mode) pin p4 7 is used for general-purpose input/output. bit 7 6 5 4 3 2 1 0 p4 7 p4 6 p4 5 p4 4 p4 3 p4 2 p4 1 p4 0 initial value 0 0 0 0 0 0 0 0 read/write r/w r/w r/w r/w r/w r/w r/w r/w 89
reset: p4ddr and p4dr and the 8-bit timer control registers are initialized, making pins p4 0 to p4 5 into input port pins with the mos pull-ups off. when the chip comes out of reset into single- chip mode (mode 3), p4 6 and p4 7 also become input port pins with the mos pull-ups off. when the chip comes out of reset into an expanded mode (mode 1 or 2), the system clock and e clock are output at p4 6 and p4 7 . hardware standby mode: all pins are placed in the high-impedance state with the mos pull-ups off. software standby mode: the 8-bit timer control registers are initialized but p4ddr and p4dr remain in their previous states. pins p4 0 to p4 5 become input or output port pins depending on the setting of p4ddr. pins p4 6 and p4 7 remain in their previous states, with system clock output remaining high and e clock output remaining low. the mos pull-ups of input pins are on or off depending on the values in p4dr. figures 5-4 to 5-7 show schematic diagrams of port 4. 90
figure 5-4. port 4 schematic diagram (pins p4 0 , p4 2 , p4 3 , and p4 5 ) p4 n r q d c r q d c internal data bus reset wp4 reset wp4d p4 n ddr p4 n dr rp4 wp4d: write port 4 ddr wp4: write port 4 rp4: read port 4 n = 0, 2, 3, 5 8-bit timer module counter clock input counter reset input figure 5-4 91
figure 5-5. port 4 schematic diagram (pins p4 1 and p4 4 ) p4 n r q d c r q d c reset wp4 reset wp4d p4 n ddr p4 n dr rp4 wp4d: write port 4 ddr wp4: write port 4 rp4: read port 4 n = 1, 4 8-bit timer module output enable 8-bit timer output internal data bus figure 5-5 92
figure 5-6. port 4 schematic diagram (pin p4 6 ) r q d c internal data bus reset wp4 p4 6 dr rp4 wp4d: write port 4 ddr wp4: write port 4 rp4: read port 4 r q d c reset wp4d p4 6 ddr figure 5-6 p4 6 hardware standby mode 1 or 2 93
figure 5-7. port 4 schematic diagram (pin p4 7 ) 5.6 port 5 port 5 is a 6-bit input/output port that also provides the input and output pins for the serial communication interface. the pin functions depend on control bits in the serial control registers. pins not used for serial communication are available for general-purpose input/output. table 5-10 lists the pin functions, which are the same in both the expanded and single-chip modes. table 5-10. port 5 pin functions (modes 1 to 3) p4 7 r q d c r q d c internal data bus hardware standby mode 3 mode 1 or 2 reset wp4 mode 3 reset s wp4d rp4 wp4d: write port 4 ddr wp4: write port 4 rp4: read port 4 mode 1 or 2 e p4 7 dr p4 7 ddr figure 5-7 usage pin functions i/o port p5 0 p5 1 p5 2 p5 3 p5 4 p5 5 serial communication txd 0 rxd 0 sck 0 txd 1 rxd 1 sck 1 94
see section 9, serial communication interface for details of the serial control bits. pins used by the serial communication interface are switched between input and output without regard to the values in the data direction register. pins of port 5 can drive a single ttl load and a 30-pf capacitive load when they are used as output pins. they can also drive a darlington pair. table 5-11 details the port 5 registers. table 5-11. port 5 registers port 5 data direction register (p5ddr)??fb8 p5ddr is an 8-bit register that selects the direction of each pin in port 5. a pin functions as an output pin if the corresponding bit in p5ddr is set to 1, and as an input pin if the bit is cleared to 0. port 5 data register (p5dr)??fba p5dr is an 8-bit register containing output data for pins p5 5 to p5 0 , and controlling their input pull- ups. when the cpu reads p5dr, for output pins (p5ddr = 1) it reads the value in the p5dr latch, but for input pins (p5ddr = 0), it obtains the logic level directly from the pin, bypassing the p5dr latch. this also applies to pins used for serial communication. mos pull-ups: are available for input pins, including serial communication input pins. software can turn the mos pull-up on by writing a 1 in p5dr, and turn it off by writing a 0. the pull-ups are automatically turned off for output pins. name abbreviation read/write initial value address port 5 data direction register p5ddr w h?0 h?fb8 port 5 data register p5dr r/w h?0 h?fba bit 7 6 5 4 3 2 1 0 p5 5 ddr p5 4 ddr p5 3 ddr p5 2 ddr p5 1 ddr p5 0 ddr initial value 1 1 0 0 0 0 0 0 read/write w w w w w w bit 7 6 5 4 3 2 1 0 p5 5 p5 4 p5 3 p5 2 p5 1 p5 0 initial value 1 1 0 0 0 0 0 0 read/write r/w r/w r/w r/w r/w r/w 95
pins p5 0 and p5 3 : these pins can be used for general-purpose input or output, or for output of serial transmit data (txd). when used for txd output, these pins are unaffected by the values in p5ddr and p5dr, and their mos pull-ups are automatically turned off. pins p5 1 and p5 4 : these pins can be used for general-purpose input or output, or for input of serial receive data (rxd). when used for rxd input, these pins are unaffected by p5ddr and p5dr, except that software can turn on their mos pull-ups by clearing their data direction bits to 0 and setting their data bits to 1. pins p5 2 and p5 5 : these pins can be used for general-purpose input or output, or for serial clock input or output (sck). when used for sck output, these pins are unaffected by p5ddr and p5dr. when these pins are used for sck input, software can turn on their mos pull-ups by clearing their data direction bits to 0 and setting their data bits to 1. reset and hardware standby mode: p5ddr and p5dr are cleared to all 0 and the serial control registers are initialized. all pins are placed in the input port (high-impedance) state with the mos pull-ups off. software standby mode: the serial control registers are initialized but p5ddr and p5dr remain in their previous states. all pins become input or output port pins depending on the setting of p5ddr. output pins output the values in p5dr. the mos pull-ups of input pins are on or off depending on the values in p5dr. figures 5-8 to 5-10 show schematic diagrams of port 5. 96
figure 5-8. port 5 schematic diagram (pins p5 0 and p5 3 ) p5 n r q d c r q d c reset wp5 reset wp5d p5 n ddr p5 n dr rp5 wp5d: write port 5 ddr wp5: write port 5 rp5: read port 5 n = 0, 3 sci module output enable serial tx data figure 5-8 internal data bus 97
figure 5-9. port 5 schematic diagram (pins p5 1 and p5 4 ) r q d c r q d reset wp5 reset wp5d p5 n ddr p5 n dr rp5 sci module input enable wp5d: write port 5 ddr wp5 write port 5 rp5: read port 5 n = 1, 4 p5 n figure 5-9 c serial rx data internal data bus 98
figure 5-10. port 5 schematic diagram (pins p5 2 and p5 5 ) 5.7 port 6 port 6 is a 7-bit input/output port that also provides input and output pins for the free-running timer, and interrupt request input pins (irq 0 to irq 2 ). the pin functions depend on control bits in the free-running timer control registers and irq enable register. pins not used for timer or interrupt functions are available for general-purpose input/output. table 5-12 lists the pin functions, which are the same in both the expanded and single-chip modes. r q d c r q d reset wp5 reset wp5d p5 n ddr p5 n dr rp5 sci module clock input enable clock input clock output enable clock output wp5d: write port 5 ddr wp5: write port 5 rp5: read port 5 n = 2, 5 p5 n c figure 5-10 internal data bus 99
table 5-12. port 6 pin functions see section 4, exception handling and section 7, free-running timer module for details of the free-running timer and interrupts. pins of port 6 can drive a single ttl load and a 90-pf capacitive load when they are used as output pins. they can also drive a darlington pair. table 5-13 details the port 6 registers. table 5-13. port 6 registers port 6 data direction register (p6ddr)??fb9 p6ddr is an 8-bit register that selects the direction of each pin in port 6. a pin functions as an output pin if the corresponding bit in p6ddr is set to 1, and as an input pin if the bit is cleared to 0. port 6 data register (p6dr)??fbb p6dr is an 8-bit register containing output data for pins p6 6 to p6 0 , and controlling their input pull- ups. when the cpu reads p6dr, for output pins (p6ddr = 1) it reads the value in the p6dr latch, but for input pins (p6ddr = 0), it obtains the logic level directly from the pin, bypassing the p6dr latch. this also applies to pins used for input and output of timer and interrupt signals. usage pin functions (modes 1 to 3) i/o port p6 0 p6 1 p6 2 p6 3 p6 4 p6 5 p6 6 timer/interrupt ftci ftoa ftob fti irq 0 irq 1 irq 2 name abbreviation read/write initial value address port 6 data direction register p6ddr w h?0 h?fb9 port 6 data register p6dr r/w h?0 h?fbb bit 7 6 5 4 3 2 1 0 p6 6 ddr p6 5 ddr p6 4 ddr p6 3 ddr p6 2 ddr p6 1 ddr p6 0 ddr initial value 1 0 0 0 0 0 0 0 read/write w w w w w w w bit 7 6 5 4 3 2 1 0 p6 6 p6 5 p6 4 p6 3 p6 2 p6 1 p6 0 initial value 0 0 0 0 0 0 0 0 read/write r/w r/w r/w r/w r/w r/w r/w 100
mos pull-ups: are available for input pins, including pins used for input of timer or interrupt signals. software can turn the mos pull-up on by writing a 1 in p6dr, and turn it off by writing a 0. the pull-ups are automatically turned off for output pins. pins p6 0 and p6 3 : as indicated in table 5-12, these pins can be used for general-purpose input or output, or for input of free-running timer clock and input capture signals. when a pin is used for free-running timer input, its p6ddr bit should be cleared to 0; otherwise the free-running timer will receive the value in p6dr. if input pull-up is not desired, the p6dr bit should also be cleared to 0. pin p6 1 and p6 2 : these pins can be used for general-purpose input or output, or for the output compare signals (ftoa and ftob) of the free-running timer. when used for ftoa or ftob output, these pins are unaffected by the values in p6ddr and p6dr, and their mos pull-ups are automatically turned off. pins p6 4 to p6 6 : these pins can be used for general-purpose input or output, or input of interrupt request signals (irq 0 to irq 2 ). when they are used for interrupt request input, their data direction bits should normally be cleared to 0, so that the value in p6dr will not generate interrupts. reset and hardware standby mode: p6ddr and p6dr are cleared to all 0. timer output and interrupt request input are disabled. all pins are placed in the input port (high-impedance) state with the mos pull-ups off. software standby mode: the free-running timer control registers are initialized but p6ddr, p6dr, and the interrupt control registers remain in their previous states. all pins become input or output port pins or interrupt request pins depending on the settings of p6ddr and the irq enable register. output pins output the values in p6dr. the mos pull-ups of input pins are on or off depending on the values in p6dr. figures 5-11 to 5-13 shows schematic diagrams of port 6. 101
figure 5-11. port 6 schematic diagram (pins p6 0 and p6 3 ) p6 n r q d c r q d c reset wp6 reset wp6d p6 n ddr p6 n dr rp6 wp6d: write port 6 ddr wp6: write port 6 rp6: read port 6 n = 0, 3 free-running timer module input-capture input, counter clock input figure 5-11 internal data bus 102
figure 5-12. port 6 schematic diagram (pins p6 1 and p6 2 ) p6 n r q d c r q d c reset wp6 reset wp6d p6 n ddr p6 n dr rp6 wp6d: write port 6 ddr wp6: write port 6 rp6: read port 6 n = 1, 2 free-running timer module output enable output-compare output internal data bus figure 5-12 103
figure 5-13. port 6 schematic diagram (pins p6 4 , p6 5 , and p6 6 ) 5.8 port 7 port 7 is an 8-bit input/output port that also provides bus control signals (in the expanded modes), and parallel handshaking control signals. table 5-14 lists the pin functions. p6 n r q d c r q d c reset wp6 reset wp6d p6 n dr rp6 irq 0 input irq 1 input irq 2 input irq enable register irq 0 enable irq 1 enable irq 2 enable internal data bus wp6d: write port 6 ddr wp6: write port 6 rp6: read port 6 n = 4 to 6 p6 n ddr figure 5-13 104
table 5-14. port 7 pin functions pins of port 7 can drive a single ttl load and a 90-pf capacitive load when they are used as output pins. table 5-15 details the port 7 registers. table 5-15. port 7 registers port 7 data direction register (p7ddr)??fbc p7ddr is an 8-bit register that selects the direction of each pin in port 7. a pin functions as an output pin if the corresponding bit in p7ddr is set to 1, and as in input pin if the bit is cleared to 0. port 7 data register (p7dr)??fbe pin expanded modes single-chip mode p7 0 p7 0 input/output or is input p7 0 input/output or is input p7 1 p7 1 input/output p7 1 input/output or os output p7 2 p7 2 input/output p7 2 input/output or busy output p7 3 p7 3 input or ios output p7 3 input/output p7 4 as output p7 4 input/output p7 5 wr output p7 5 input/output p7 6 rd output p7 6 input/output p7 7 wait input p7 7 input/output name abbreviation read/write initial value address port 7 data direction register p7ddr w h?0 h?fbc port 7 data register p7dr r/w h?0 h?fbe bit 7 6 5 4 3 2 1 0 p7 7 ddr p7 6 ddr p7 5 ddr p7 4 ddr p7 3 ddr p7 2 ddr p7 1 ddr p7 0 ddr initial value 0 0 0 0 0 0 0 0 read/write w w w w w w w w bit 7 6 5 4 3 2 1 0 p7 7 p7 6 p7 5 p7 4 p7 3 p7 2 p7 1 p7 0 initial value 0 0 0 0 0 0 0 0 read/write r/w r/w r/w r/w r/w r/w r/w r/w 105
p7dr is an 8-bit register containing output data for pins p7 7 to p7 0 , and controlling their input pull- ups. when the cpu reads p7dr, for output pins (p7ddr = 1) it reads the value in the p7dr latch, but for input pins (p7ddr = 0), it obtains the logic level directly from the pin, bypassing the p7dr latch. this also applies to pins used for control signal input or output. mos pull-ups: are available for input pins, including pins used for input of the is and wait signals. software can turn the mos pull-up on by writing a 1 in p7dr, and turn it off by writing a 0. the pull-ups are automatically turned off for output pins. pin p7 0 : can be used for general-purpose input or output, or input of the input strobe (is) parallel handshake signal. when p7 0 is used for is input, p7 0 ddr should be cleared to 0, so that output from p7dr will not cause unintended strobes. if input pull-up is not desired, p7 0 dr should also be cleared to 0. pins p7 1 and p7 2 : in modes 1 and 2 (expanded modes), these pins can be used for general-purpose input or output. in mode 3 (single-chip mode), these pins can be used for general-purpose input or output or for output of the os and busy parallel handshake signals, depending on the ose and bse bits in the handshake control/status register. see section 6, parallel handshaking interface, for further information. pins used for parallel handshaking output are unaffected by the values in p7ddr and p7dr, and their mos pull-ups are automatically turned off. pin p7 3 : in modes 1 and 2 (expanded modes) p7 3 is used for ios output if p7 3 ddr is set to 1, and for general-purpose input if p7 3 ddr is cleared 0. it cannot be used for general-purpose output. in mode 3 (single-chip mode), pin p7 3 can be used for general-purpose input or output. pins p7 4 , p7 5 , and p7 6 : in modes 1 and 2 (expanded modes), these pins are used for output of the as, rd, and wr bus control signals. they are unaffected by the values in p7ddr and p7dr, and their mos pull-ups are automatically turned off. in mode 3 (single-chip mode), these pins can be used for general-purpose input or output. pin p7 7 : in modes 1 and 2, this pin is used for input of the wait bus control signal. it is unaffected by the values in p7ddr and p7dr, except that software can turn on its mos pull-up by clearing its data direction bit to 0 and setting its data bit to 1. 106
in mode 3 (single-chip mode), this pin can be used for general-purpose input or output. reset: in the single-chip mode (mode 3), a reset initializes all pins of port 7 to the general-purpose input state with the mos pull-ups off. in the expanded modes (modes 1 and 2), p7 0 to p7 3 are initialized as input port pins, and p7 4 to p7 7 are initialized to their bus control functions. hardware standby mode: all pins are placed in the high-impedance state with the mos pull-ups off. software standby mode: all pins remain in their previous state. for rd, wr, and as this means the high output state. figures 5-14 to 5-18 show schematic diagrams of port 7. 107
figure 5-14. port 7 schematic diagram (pin p7 0 ) p7 0 r q d c r q d c reset wp7 reset wp7d p7 0 ddr p7 0 dr rp7 wp7d: write port 7 ddr wp7: write port 7 rp7: read port 7 figure 5-14 internal data bus is input 108
figure 5-15. port 7 schematic diagram (pins p7 1 and p7 2 ) p7 n r q d c r q d c reset wp7 reset wp7d p7 n ddr p7 n dr rp7 ose wp7d: write port 7 ddr wp7: write port 7 rp7 : read port 7 n = 1, 2 figure 5-15 bse os output busy output handshake control status register internal data bus 109
figure 5-16. port 7 schematic diagram (pin p7 3 ) p7 3 r q d c r q d c mode 3 mode 1 or 2 reset wp7 reset wp7d p7 3 ddr p7 3 dr rp7 wp7d: write port 7 ddr wp7: write port 7 rp7: read port 7 ios output figure 5-16 internal data bus 110
figure 5-17. port 7 schematic diagram (pins p7 4 , p7 5 , and p7 6 ) p7 n r q d c r q d c mode 3 mode 1 or 2 reset wp7 reset wp7d p7 n ddr p7 n dr rp7 wp7d: write port 7 ddr wp7: write port 7 rp7: read port 7 n = 4, 5, 6 as output wr output rd output figure 5-17 hardware standby mode 1 or 2 internal data bus 111
figure 5-18. port 7 schematic diagram (pin p7 7 ) p7 7 r q d c internal data bus reset wp7 r q d c reset wp7d p7 7 ddr p7 7 dr rp7 wp7d: write port 7 ddr wp7: write port 7 rp7: read port 7 figure 5-18 mode 1 or 2 wait input 112
section 6. parallel handshaking interface 6.1 overview in single-chip mode (mode 3), the h8/325 series chips can interface to another device by parallel handshaking, using port 3. 6.1.1 features ? built-in latch circuits data input to port 3 can be latched on the falling edge of the is signal. ? strobe signal output a strobe signal can be output on the os line when port 3 is written or read. ? busy signal output a busy signal is output on the busy line from the time when data are latched on the falling edge of is until the latched data are read, unlocking the latch. ? input strobe interrupt an input strobe interrupt can be generated at the falling edge of the is signal. ? recovery from software standby mode the input strobe interrupt can be used to recover from software standby mode. 113
6.1.2 block diagram figure 6-1 is a block diagram of the parallel handshaking interface. figure 6-1. block diagram of parallel handshaking interface p3 n r q d c r q d c internal data bus reset wp3d reset wp3 p3 n dr p3 n ddr rp3 wp3: rp3: wp3d: n =0 to7 figure 6-1 c d q hcsr os busy is isi interrupt signal control logic port 3 input latch write port 3 read port 3 write port 3 ddr 114
6.1.3 input and output pins table 6-1 lists the input and output pins used by the parallel handshaking interface. table 6-1. input and output pins of parallel handshaking interface name abbreviation i/o function data input/output pins p3 7 ?p3 0 i/o data input and output input strobe is i strobe for input data output strobe os o strobe for output data busy busy o busy signal 6.1.4 register configuration table 6-2 lists information about the parallel handshaking interface registers. table 6-2. register configuration name abbreviation r/w initial value address port 3 data direction register p3ddr w h'00 h'ffb4 port 3 data register p3dr r/w h'00 h'ffb6 handshake control/status register hcsr r/w h'03 h'fffe 6.2 register descriptions 6.2.1 port 3 data direction register (p3ddr) to use the parallel handshaking interface for input, clear p3ddr to h'00. for output, set p3ddr to h'ff. do not set the bits individually. see section 5.4, port 3 for further information. bit 7 6 5 4 3 2 1 0 p3 7 ddr p3 6 ddr p3 5 ddr p3 4 ddr p3 3 ddr p3 2 ddr p3 1 ddr p3 0 ddr initial value 0 0 0 0 0 0 0 0 read/write w w w w w w w w 115
6.2.2 port 3 data register (p3dr) when the parallel handshaking interface is used for output (p3ddr = h'ff), p3dr stores the output data. if port 3 is read, the p3dr data are obtained. when the parallel handshaking interface is used for input (p3ddr = h'00), p3dr has separate latches for reading and writing. the data written in p3dr control the mos input pull-ups. when p3dr is read, data are obtained from the separate input latches if the input strobe flag (isf) is set to 1, or directly from the input pins if isf is cleared to 0. see section 5.4, port 3 for further information. 6.2.3 handshake control/status register (hcsr) hcsr is an 8-bit register containing control and status information for parallel handshaking. in the reset and hardware standby modes, hcsr is initialized to h'03. in the software standby mode it retains its previous value. bit 7?nput strobe flag (isf): indicates that the input strobe signal (is) has gone low. isf is a read-only bit that is set and cleared by hardware. it is set by strobe input. it is cleared when the port 3 data register is written or read. (the handshake control/status register must be read first.) bit 7 isf description 0 to clear isf, the cpu must read hcsr after isf has been (initial value) set to 1, then read or write the port 3 data register (p3dr). 1 isf is set to 1 on the falling edge of is. bit 7 6 5 4 3 2 1 0 p3 7 p3 6 p3 5 p3 4 p3 3 p3 2 p3 1 p3 0 initial value 0 0 0 0 0 0 0 0 read/write r/w r/w r/w r/w r/w r/w r/w r/w bit 7 6 5 4 3 2 1 0 isf isie ose oss lte bse initial value 0 0 0 0 0 0 1 1 read/write r r/w r/w r/w r/w r/w 116
bit 6?nput strobe interrupt enable (isie): enables or disables the handshake interrupt request (isi). bit 6 isie description 0 the handshake interrupt request (isi) is disabled. (initial value) 1 the handshake interrupt request (isi) is enabled. bit 5?utput strobe enable (ose): enables or disables output of the output strobe signal. do not set ose to 1 in the expanded modes (modes 1 and 2). bit 5 ose description 0 the output strobe signal is disabled. (initial value) 1 the output strobe signal is enabled. bit 4?utput strobe select (oss): selects whether to generate an output strobe signal when the port 3 data register (p3dr) is written, or when it is read. bit 4 oss description 0 an output strobe signal is output when p3dr is read. (initial value) 1 an output strobe signal is output when p3dr is written. bit 3?atch enable (lte): controls the input latches of port 3. do not set lte to 1 in the expanded modes (modes 1 and 2). when lte is set to 1, input data are latched on the falling edge of is. the data are retained in the input latch until the port 3 data register (p3dr) is read, after which the next data can be latched. bit 3 lte description 0 port 3 input data are not latched. (initial value) 1 port 3 input data are latched on the falling edge of is. 117
bit 2?usy enable (bse): this bit enables or disables output of the busy signal. do not set bse to 1 in the expanded modes (modes 1 and 2). bit 2 isie description 0 busy signal output is disabled. (initial value) 1 busy signal output is enabled. bits 1 and 0?eserved: these bits cannot be modified and are always read as 1. 6.3 operation 6.3.1 output timing of output strobe signal the output strobe signal is output when the port 3 data register (p3dr) is written or read. the output strobe signal goes low at the seventh system clock cycle after p3dr is written or read, remains low for eight system clock cycles, then goes high. figure 6-2 shows how the output strobe signal is output after p3dr is written (when oss = 1). note the following point when reading or writing p3dr twice consecutively. if p3dr is written or read once, then written or read again within 15 states, the output strobe signal is not output for the second write or read. figure 6-3 shows an example of this when oss = 1. figure 6-2. output strobe output timing (when oss = 1) fig 6-2 port 3 os port 3 write 7 system clocks 8 system clocks 118
figure 6-3. output strobe output timing (consecutive writing of port 3 when oss = 1) 6.3.2 busy signal output timing the busy signal remains low from the fall of the input strobe signal until the data latched in port 3 have been read, unlocking the latch. figure 6-4 shows an example. while the busy signal is low, data input to port 3 are not latched, even if the input strobe signal goes low again. figure 6-4. busy signal output timing 6.3.3 operation in software standby mode in software standby mode, the os and busy output pins retain their previous states. for timing of the output strobe signal, the entire time during when the chip is in software standby mode is counted as zero system clock cycles. figure 6-5 shows an example. fig 6-3 port 3 os port 3 write port 3 write not output fig 6-4 is busy port 3 read 119
figure 6-5. output strobe timing in software standby mode when the isie and lte bits in the handshake control/status register (hcsr) are both set to 1, if a high-to-low transition of the is signal occurs during software standby mode, an input strobe interrupt is requested and the chip recovers from software standby mode to handle the interrupt. if the parallel handshaking interface is set for input, the port 3 input data are also latched. if either the isie or lte bit is cleared to 0, then high-to-low transitions of the is signal are ignored during software standby mode. 6.3.4 sample application figure 6-6 shows an example in which the parallel handshaking interface is used to interconnect two h8/325 chips. figure 6-7 shows the interface timing. figure 6-6. sample usage of parallel handshaking interface fig 6-5 port 3 os port 3 write t t t + t = 7 system clocks software standby mode clock settling time same state held same data held 1 2 1 2 fig 6-6 p3 to p3 os is p3 to p3 is os h8/325 (sending chip) h8/325 (receiving chip) 7 0 7 0 120
figure 6-7. parallel handshaking interface timing chart (example) 1. the sending and receiving h8/325s set their hcsr bits as follows: sending h8/325: isie = 1, ose = 1, oss = 1, lte = 0, bse = 0. receiving h8/325: isie = 1, ose = 1, oss = 0, lte = 1, bse = 0. 2. the sending h8/325 writes the transmit data in the port 3 data register (p3dr). this generates an output strobe signal, notifying the receiving h8/325 of data output. 3. the receiving h8/325 receives the strobe on its input strobe line and latches the data in port 3. isf is set to 1, generating an input strobe interrupt. 4. the receiving h8/325 reads hcsr, then reads the received data from p3dr. this clears isf to 0 and generates an output strobe signal, notifying the sending h8/325 that the data have been received. 5. the input strobe line of the sending h8/325 goes low, setting isf and generating an input strobe interrupt. 6. the sending h8/325 reads hcsr, then writes the next transmit data in p3dr. (if it has no next data to send, it should read p3dr.) this clears isf to 0 and generates an output strobe signal. the process now returns to step 3. 6.3.5 interrupts regardless of the operating mode or the value of the lte bit, isf is always set to 1 when the is input changes from high to low. if isie is set to 1, an input strobe interrupt (isi) is requested. in the software standby mode, lte must also be set. see section 6.3.3, operation in software standby mode. fig 6-7 sending h8/325 receiving h8/325 write p3dr interrupt request write p3dr interrupt request read hcsr read p3dr p3 to p3 os is h8/325 (sending chip) p3 to p3 is os h8/325 (receiving chip) 7 0 7 0 read hcsr p3dr: port 3 data register hcsr: handshake control/status register 121
section 7. 16-bit free-running timer 7.1 overview the h8/325 series has an on-chip 16-bit free-running timer (frt) module that uses a 16-bit free- running counter as a time base. applications of the frt module include rectangular-wave output (up to two independent waveforms), input pulse width measurement, and measurement of external clock periods. 7.1.1 features the features of the free-running timer module are listed below. selection of four clock sources the free-running counter can be driven by an internal clock source (/2, /8, or /32), or an external clock input (enabling use as an external event counter). two independent comparators each comparator can generate an independent waveform. input capture the current count can be captured on the rising or falling edge (selectable) of an input signal. counter can be cleared under program control the free-running counter can be cleared on compare-match a. four interrupt sources compare-match a and b, input capture, and overflow interrupts are requested independently. noise canceler a built-in noise canceler can remove high-frequency noise from the pulse signal input at the input capture pin. 7.1.2 block diagram figure 7-1 shows a block diagram of the free-running timer. 123
figure 7-1. block diagram of 16-bit free-running timer external clock source internal clock sources clock select comparator a ocra (h/l) comparator b ocrb (h/l) bus interface internal data bus /2 /8 /32 ftci compare- clear clock ftoa ftob overflow icr (h/l) match a compare- match b capture frc (h/l) tcsr fti control logic module data bus fovi ocib interrupt signals ici ocia legend ocra: ocrb: frc: icr: tcsr: tcr: output compare register a output compare register b free-running counter input capture register timer control/status register timer control register figure7-1 tcr 124
7.1.3 input and output pins table 7-1 lists the input and output pins of the free-running timer module. table 7-1. input and output pins of free-running timer module 7.1.4 register configuration table 7-2 lists the registers of the free-running timer module. table 7-2. register configuration * software can write a 0 to clear bits 7 to 4, but cannot write a 1 in these bits. name abbreviation i/o function counter clock input ftci input input of external free-running counter clock signal output compare a ftoa output output controlled by comparator a output compare b ftob output output controlled by comparator b input capture fti input input capture trigger initial name abbreviation r/w value address timer control register tcr r/w h?0 h?f90 timer control/status register tcsr r/(w)* h?0 h?f91 free-running counter (high) frc (h) r/w h?0 h?f92 free-running counter (low) frc (l) r/w h?0 h?f93 output compare register a (high) ocra (h) r/w h?f h?f94 output compare register a (low) ocra (l) r/w h?f h?f95 output compare register b (high) ocrb (h) r/w h?f h?f96 output compare register b (low) ocrb (l) r/w h?f h?f97 input capture register (high) icr (h) r h?0 h?f98 input capture register (low) icr (l) r h?0 h?f99 frt noise canceler control register fncr r/w h'fc h?fff 125
7.2 register descriptions 7.2.1 free-running counter (frc) ?h?f92 the frc is a 16-bit readable/writable up-counter that increments on an internal pulse generated from a clock source. the clock source is selected by the clock select 1 and 0 bits (cks1 and cks0) of the timer control register (tcr). when the frc overflows from h?fff to h?000, the overflow flag (ovf) in the timer control/status register (tcsr) is set to 1. because the frc is a 16-bit register, a temporary register (temp) is used when the frc is written or read. see section 7.3, cpu interface for details. the frc is initialized to h?000 at a reset and in the standby modes. it can also be cleared by compare-match a. 7.2.2 output compare registers a and b (ocra and ocrb) ?h?f94 and h?f96 ocra and ocrb are 16-bit readable/writable registers, the contents of which are continually compared with the value in the frc. when a match is detected, the corresponding output compare flag (ocfa or ocfb) is set in the timer control/status register (tcsr). bit 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 initial 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 value read/ r/w r/w r/w r/w r/w r/w r/w r/w r/w r/w r/w r/w r/w r/w r/w r/w write bit 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 initial 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 value read/ r/w r/w r/w r/w r/w r/w r/w r/w r/w r/w r/w r/w r/w r/w r/w r/w write 126
in addition, if the output enable bit (oea or oeb) in the timer output compare control register (tcr) is set to 1, when the output compare register and frc values match, the logic level selected by the output level bit (olvla or olvlb) in the tcsr is output at the output compare pin (ftoa or ftob). because ocra and ocrb are 16-bit registers, a temporary register (temp) is used for write access, as explained in section 7.3, cpu interface. ocra and ocrb are initialized to h?fff at a reset and in the standby modes. 7.2.3 input capture register (icr) ?h?f98 the input capture register is a 16-bit read-only register. when the rising or falling edge of the signal at the input capture pin (fti) is detected, the current value of the frc is copied to the input capture register (icr). at the same time, the input capture flag (icf) in the timer control/status register (tcsr) is set to 1. the input capture edge is selected by the input edge select bit (iedg) in the tcsr. because the input capture register is a 16-bit register, a temporary register (temp) is used when it is read. see section 7.3, cpu interface for details. to ensure input capture, when the noise canceler is not used, the width of the input capture pulse (fti) should be at least 1.5 system clock cycles (1.5). bit 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 initial 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 value read/ r r r r r r r r r r r r r r r r write 127
figure 7-2. minimum input capture pulse width (noise canceler disabled) the input capture register is initialized to h?000 at a reset and in the standby modes. note: when input capture is detected, the frc value is transferred to the input capture register even if the input capture flag is already set. 7.2.4 timer control register (tcr) ?h?f90 the tcr is an 8-bit readable/writable register that enables and disables output signals and interrupts, and selects the timer clock source. the tcr is initialized to h?0 at a reset and in the standby modes. bit 7 ?input capture interrupt enable (icie): selects whether to request an input capture interrupt (ici) when the input capture flag (icf) in the timer status/control register (tcsr) is set to 1. bit 6 ?output compare interrupt b enable (ocibe): selects whether to request output compare interrupt b (ocib) when output compare flag b (ocfb) in the timer status/control register (tcsr) is set to 1. ftia, ftib, ftic, or ftid fig 7-2 bit 7 6 5 4 3 2 1 0 icie ocieb ociea ovie oeb oea cks1 cks0 initial value 0 0 0 0 0 0 0 0 read/write r/w r/w r/w r/w r/w r/w r/w r/w bit 7 icie description 0 input capture interrupt request (ici) is disabled. (initial value) 1 input capture interrupt request (ici) is enabled. 128
bit 5 ?output compare interrupt a enable (ociae): selects whether to request output compare interrupt a (ocia) when output compare flag a (ocfa) in the timer status/control register (tcsr) is set to 1. bit 4 ?timer overflow interrupt enable (ovie): selects whether to request a free-running timer overflow interrupt (fovi) when the timer overflow flag (ovf) in the timer status/control register (tcsr) is set to 1. bit 3 ?output enable b (oeb): enables or disables output of the output compare b signal (ftob). if output compare b is enabled, the ftob pin is driven to the level selected by olvlb in the timer status/control register (tcsr) whenever the frc value matches the value in output compare register b (ocrb). bit 2 ?output enable a (oea): enables or disables output of the output compare a signal (ftoa). if output compare a is enabled, the ftoa pin is driven to the level selected by olvla in the timer status/control register (tcsr) whenever the frc value matches the value in output compare register a (ocra). bit 6 ocibe description 0 output compare interrupt request b (ocib) is disabled. (initial value) 1 output compare interrupt request b (ocib) is enabled. bit 5 ociae description 0 output compare interrupt request a (ocia) is disabled. (initial value) 1 output compare interrupt request a (ocia) is enabled. bit 4 ovie description 0 timer overflow interrupt request (fovi) is disabled. (initial value) 1 timer overflow interrupt request (fovi) is enabled. bit 3 oeb description 0 output compare b output is disabled. (initial value) 1 output compare b output is enabled. 129
bits 1 and 0 ?clock select (cks1 and cks0): these bits select external clock input or one of three internal clock sources for the frc. external clock pulses are counted on the rising edge. 7.2.5 timer control/status register (tcsr) ?h?f91 * software can write a 0 in bits 7 to 4 to clear the flags, but cannot write a 1 in these bits. the tcsr is an 8-bit readable and partially writable register that contains the four interrupt flags and selects the output compare levels, input capture edge, and whether to clear the counter on compare-match a. the tcsr is initialized to h?0 at a reset and in the standby modes. bit 7 ?input capture flag (icf): this status bit is set to 1 to flag an input capture event, indicating that the frc value has been copied to the icr. icf must be cleared by software. it is set by hardware, however, and cannot be set by software. bit 2 oea description 0 output compare a output is disabled. (initial value) 1 output compare a output is enabled. bit 1 bit 0 cks1 cks0 description 0 0 /2 internal clock source (initial value) 0 1 /8 internal clock source 1 0 /32 internal clock source 1 1 external clock source (rising edge) bit 7 6 5 4 3 2 1 0 icf ocfb ocfa ovf olvlb olvla iedg cclra initial value 0 0 0 0 0 0 0 0 read/write r/(w)* r/(w)* r/(w)* r/(w)* r/(w) r/(w) r/(w) r/w 130
bit 6 ?output compare flag b (ocfb): this status flag is set to 1 when the frc value matches the ocrb value. this flag must be cleared by software. it is set by hardware, however, and cannot be set by software. bit 5 ?output compare flag a (ocfa): this status flag is set to 1 when the frc value matches the ocra value. this flag must be cleared by software. it is set by hardware, however, and cannot be set by software. bit 4 ?timer overflow flag (ovf): this status flag is set to 1 when the frc overflows (changes from h?fff to h?000). this flag must be cleared by software. it is set by hardware, however, and cannot be set by software. bit 7 icf description 0 to clear icf, the cpu must read icf after it (initial value) has been set to 1, then write a 0 in this bit. 1 this bit is set to 1 when an fti input signal causes the frc value to be copied to the icr. bit 6 ocfb description 0 to clear ocfb, the cpu must read ocfb after (initial value) it has been set to 1, then write a 0 in this bit. 1 this bit is set to 1 when frc = ocrb. bit 5 ocfa description 0 to clear ocfa, the cpu must read ocfa after (initial value) it has been set to 1, then write a 0 in this bit. 1 this bit is set to 1 when frc = ocra. 131
bit 3 ?output level b (olvlb): selects the logic level output at the ftob pin when the frc and ocrb values match. bit 2 ?output level a (olvla): selects the logic level output at the ftoa pin when the frc and ocra values match. bit 1 ?input edge select (iedg): selects the rising or falling edge of the input capture signal (fti). bit 0 ?counter clear a (cclra): selects whether to clear the frc at compare-match a (when the frc and ocra values match). bit 4 ovf description 0 to clear ovf, the cpu must read ovf after (initial value) it has been set to 1, then write a 0 in this bit. 1 this bit is set to 1 when frc changes from h?fff to h?000. bit 3 olvlb description 0 a 0 logic level is output for compare-match b. (initial value) 1 a 1 logic level is output for compare-match b. bit 2 olvla description 0 a 0 logic level is output for compare-match a. (initial value) 1 a 1 logic level is output for compare-match a. bit 1 iedg description 0 frc contents are transferred to icr on the falling edge of fti. (initial value) 1 frc contents are transferred to icr on the rising edge of fti. bit 0 cclra description 0 the frc is not cleared. (initial value) 1 the frc is cleared at compare-match a. 132
7.2.6 frt noise canceler control register (fncr) ?h?fff the fncr is an 8-bit readable/writable register that controls the input capture noise canceler. the fncr is initialized to h?c at a reset and in the standby modes. bits 7 to 2 ?reserved: these bits cannot be modified, and are always read as 1. bits 1 and 0 ?noise canceler select 1 and 0 (ncs1 and ncs0): select the sampling clock provided to the noise canceler. three internal clock rates can be selected. the noise canceler recognizes a level change only if it is observed in four consecutive samples. when the noise canceler is enabled, the input capture pulse width must be at least four sampling clock cycles. see section 7.6, noise canceler for further information. the noise canceler can be disabled by clearing both ncs1 and ncs0 to 0. the input capture pulse width must then be at least 1.5 system clock cycles (1.5 . ) to assure capture. 7.3 cpu interface the free-running counter (frc), output compare registers (ocra and ocrb), and input capture register (icr) are 16-bit registers, but they are connected to an 8-bit data bus. when the cpu accesses these registers, to ensure that both bytes are written or read simultaneously, the access is performed using an 8-bit temporary register (temp). bit 7 6 5 4 3 2 1 0 ncs1 ncs0 initial value 1 1 1 1 1 1 0 0 read/write r/w r/w bit 1 bit 0 ncs1 ncs0 description 0 0 noise canceler is disabled. (initial value) 0 1 sampling clock frequency: /32 1 0 sampling clock frequency: /64 1 1 sampling clock frequency: /128 133
these registers are written and read as follows: register write when the cpu writes to the upper byte, the byte of write data is placed in temp. next, when the cpu writes to the lower byte, this byte of data is combined with the byte in temp and all 16 bits are written in the register simultaneously. register read when the cpu reads the upper byte, the upper byte of data is sent to the cpu and the lower byte is placed in temp. when the cpu reads the lower byte, it receives the value in temp. (as an exception, when the cpu reads ocra or ocrb, it reads both the upper and lower bytes directly, without using temp.) programs that access these registers should normally use word access. equivalently, they may access first the upper byte, then the lower byte by two consecutive byte accesses. data will not be transferred correctly if the bytes are accessed in reverse order, if only one byte is accessed, or if the upper and lower bytes are accessed separately and another register is accessed in between, altering the value in temp. coding examples to write the contents of general register r0 to ocra: mov.w r0, @ocra to transfer the icr contents to general register r0: mov.w @icr, r0 figure 7-3 shows the data flow when the frc is accessed. the other registers are accessed in the same way. 134
figure 7-3 (a). write access to frc (when cpu writes h?a55) module data bus (1) upper byte write bus interface cpu writes data h?a frc h [ ] frc l [ ] temp [h?a] (2) lower byte write bus interface module data bus cpu writes data h?5 temp [h?a] frc h [h?a] frc l [h?5] fig 7-3 (a) 135
figure 7-3 (b). read access to frc (when frc contains h?a55) 7.4 operation 7.4.1 frc incrementation timing the frc increments on a pulse generated once for each cycle of the selected (internal or external) clock source. (1) internal clock sources: can be selected by the cks1 and cks0 bits in the tcr. internal clock sources are created by dividing the system clock (). three internal clock sources are available: /2, /8, and /32. figure 7-4 shows the increment timing. (1) upper byte read bus interface module data bus cpu writes data h?a temp [h?5] frc h [h?a] frc l [h?5] (2) lower byte read bus interface module data bus cpu writes data h?5 temp [h?5] frc h [ ] frc l [ ] fig 7-3 (b) 136
figure 7-4. increment timing for internal clock source (2) external clock input: can be selected by the cks1 and cks0 bits in the tcr. the frc increments on the rising edge of the ftci clock signal. the pulse width of the external clock signal must be at least 1.5 system clock () cycles. the counter will not increment correctly if the pulse width is shorter than this. figure 7-5 shows the increment timing. figure 7-6 shows the minimum external clock pulse width. figure 7-5. increment timing for external clock source prescaler output frc clock pulse frc n ?1 n n + 1 fig 7-4 n n + 1 ftci frc frc clock pulse fig 7-5 137
figure 7-6. minimum external clock pulse width 7.4.2 output compare timing when a compare-match occurs, the logic level selected by the output level bit (olvla or olvlb) in the tcsr is output at the output compare pin (ftoa or ftob). figure 7-7 shows the timing of this operation for compare-match a. figure 7-7. timing of output compare a 7.4.3 frc clear timing if the cclra bit in the tcsr is set to 1, the frc is cleared when compare-match a occurs. figure 7-8 shows the timing of this operation. ftci fig 7-6 internal compare- match a signal olvla ftoa * cleared by software frc ocra n n n n + 1 clear * n n + 1 fig 7-7 138
figure 7-8. clearing of frc by compare-match a 7.4.4 input capture timing (1) input capture timing without noise canceler: an internal input capture signal is generated from the rising or falling edge of the fti input, as selected by the iedg bit in the tcsr. figure 7- 9 shows the usual input capture timing when the rising edge is selected (iedg = 1). figure 7-9. input capture timing (usual case) if the upper byte of the icr is being read when the internal input capture signal should be generated, the internal input capture signal is delayed by one state. figure 7-10 shows the timing for this case. internal compare- match a signal frc n h'0000 fig 7-8 input at fti pin internal input capture signal fig 7-9 139
figure 7-10. input capture timing (1-state delay due to icr read) (2) input capture timing with noise canceler: the noise canceler samples the fti input, and does generate an internal input capture signal until three to four sampling clock cycles after the rise or fall of fti. figure 7-9 shows the timing. if the upper byte of the icr is being read when the internal input capture signal should be generated, the internal input capture signal is additionally delayed by one system clock cycle (). figure 7-11. input capture timing with noise cancellation 7.4.5 timing of input capture flag (icf) setting the input capture flag icf is set to 1 by the internal input capture signal. the frc contents are transferred to the icr at the same time. figure 7-12 shows the timing of this operation. icr upper byte read cycle t 1 t 2 t 3 input at fti pin internal input capture signal fig 7-10 fig 7-11 fti sampling clock noise canceler output internal input capture signal 140
figure 7-12. setting of input capture flag 7.4.6 setting of frc overflow flag (ovf) the frc overflow flag (ovf) is set to 1 when the frc changes from h?fff to h?000. figure 7-13 shows the timing of this operation. figure 7-13. setting of overflow flag (ovf) internal input capture signal icf frc icr n n figure 7-12 ovf frc h'ffff h'0000 fig 7-13 internal overflow signal 141
7.5 interrupts the free-running timer channel can request four types of interrupts: input capture (ici), output compare a and b (ocia and ocib), and overflow (fovi). each interrupt is requested when the corresponding flag bit is set, provided the corresponding enable bit is also set. independent signals are sent to the interrupt controller for each type of interrupt. table 7-3 lists information about these interrupts. table 7-3. free-running timer interrupts 7.6 noise canceler the noise canceler acts as a digital low-pass filter, rejecting high-frequency pulses received at the input capture (fti) pin. figure 7-14 shows a block diagram of the noise canceler. the noise canceler consists of four latches connected in series, and a circuit that detects when all four latches contain the same value. the fti input is sampled on the rising edge of the sampling clock selected by the ncs1 and ncs0 bits. when all four latches contain the same value, this value is regarded as valid and output from the noise canceler. if all four latches are not the same, the noise canceler holds its previous output. immediately after a reset, the noise canceler output is 0. to assure capture, the pulse input at the fti pin must be at least four sampling clock cycles wide. the noise canceler control register (fncr) provides a selection of three sampling clock rates and the option of disabling the noise canceler. table 7-4 indicates the cycle times of the sampling clock for various settings. interrupt description priority ici requested when icf and icie are set high ocia requested when ocfa and ociae are set ocib requested when ocfb and ocibe are set fovi requested when ovf and ovie are set low 142
figure 7-14. noise canceler block diagram table 7-4. sampling clock cycle for various system clock frequencies figure 7-15 shows an example of noise cancellation. in this example, an input capture pulse narrower than four sampling clock cycles is rejected as noise. fig 7-14 sampling signal fti input latch c d q latch c d q latch c d q latch c d q agreement detector sampling signal ?t ?t: selected by ncs1 and ncs0 noise canceler output ? t ? t: selected by ncs1 and ncs0 sampling system clock () frequency (mhz) ncs1 ncs0 clock 10 8 6 4 2 1 0.5 0 0 0 1 /32 3.2 4.0 5.3 8.0 16.0 32.0 64.0 1 0 /64 6.4 8.0 10.7 16.0 32.0 64.0 128.0 1 1 /128 12.8 16.0 21.3 32.0 64.0 128.0 256.0 (unit: s) 143
figure 7-15. noise cancellation (example) 7.7 sample application in the example below, the free-running timer channel is used to generate two square-wave outputs with a 50% duty factor and arbitrary phase relationship. the programming is as follows: (1) the cclra bit in the tcsr is set to 1. (2) each time a compare-match interrupt occurs, software inverts the corresponding output level bit in the tcsr (olvla or olvlb). figure 7-16. square-wave output (example) fig 7-15 fti sampling clock noise canceler output rejected as noise frc h?fff ocra ocrb h?000 ftoa ftob clear counter fig 7-16 144
7.8 application notes application programmers should note that the following types of contention can occur in the free- running timer. (1) contention between frc write and clear: if an internal counter clear signal is generated during the t 3 state of a write cycle to the lower byte of the free-running counter, the clear signal takes priority and the write is not performed. figure 7-17 shows this type of contention. figure 7-17. frc write-clear contention (2) contention between frc write and increment: if an frc increment pulse is generated during the t 3 state of a write cycle to the lower byte of the free-running counter, the write takes priority and the frc is not incremented. figure 7-18 shows this type of contention. frc lower byte write cycle frc address n h'0000 t 1 t 2 t 3 internal address bus internal write signal frc clear signal frc fig 7-17 145
figure 7-18. frc write-increment contention (3) contention between ocr write and compare-match: if a compare-match occurs during the t 3 state of a write cycle to the lower byte of ocra or ocrb, the write takes precedence and the compare-match signal is inhibited. figure 7-19 shows this type of contention. frc lower byte write cycle frc address internal address bus internal write signal frc clock pulse frc n m t t t write data 1 2 3 fig 7-18 146
figure 7-19. contention between ocr write and compare-match (4) incrementation caused by changing of internal clock source: when an internal clock source is changed, the changeover may cause the frc to increment. this depends on the time at which the clock select bits (cks1 and cks0) are rewritten, as shown in table 7-5. the pulse that increments the frc is generated at the falling edge of the internal clock source. if clock sources are changed when the old source is high and the new source is low, as in case no. 3 in table 7-5, the changeover generates a falling edge that triggers the frc increment clock pulse. switching between an internal and external clock source can also cause the frc to increment. ocra or ocrb lower byte write cycle ocr address n n + 1 n m inhibited write data internal address bus internal write signal compare-match a or b signal ocra or ocrb frc t 1 t t 2 3 fig 7-19 147
table 7-5. effect of changing internal clock sources no. description timing chart low low: cks1 and cks0 are 1 rewritten while both clock sources are low. low high: cks1 and cks0 are 2 rewritten while old clock source is low and new clock source is high. high low: cks1 and cks0 are 3 rewritten while old clock source is high and new clock source is low. * the switching of clock sources is regarded as a falling edge that increments the frc. old clock source new clock source frc clock pulse frc cks rewrite n n + 1 table 7-5 (a) old clock source new clock source frc clock pulse frc cks rewrite n n + 1 n + 2 table 7-5 (b) old clock source new clock source frc clock pulse frc n n + 1 n + 2 cks rewrite * table 7-5 (c) 148
table 7-5. effect of changing internal clock sources (cont.) no. description timing chart high high: cks1 and cks0 are 4 rewritten while both clock sources are high. old clock source new clock source frc clock pulse frc n n + 1 cks rewrite n + 2 table 7-5 (d) 149
section 8. 8-bit timers 8.1 overview the h8/325 series chips include an 8-bit timer module with two channels. each channel has an 8-bit counter (tcnt) and two time constant registers (tcora and tcorb) that are constantly compared with the tcnt value to detect compare-match events. one application of the 8-bit timer module is to generate a rectangular-wave output with an arbitrary duty factor. 8.1.1 features the features of the 8-bit timer module are listed below. selection of four clock sources the counters can be driven by an internal clock signal (/8, /64, or /1024) or an external clock input (enabling use as an external event counter). selection of three ways to clear the counters the counters can be cleared on compare-match a or b, or by an external reset signal. timer output controlled by two time constants the timer output signal in each channel is controlled by two independent time constants, enabling the timer to generate output waveforms with an arbitrary duty factor. three independent interrupts compare-match a and b and overflow interrupts can be requested independently. 8.1.2 block diagram figure 8-1 shows a block diagram of one channel in the 8-bit timer module. the other channel is identical. 151
figure 8-1. block diagram of 8-bit timer 8.1.3 input and output pins table 8-1 lists the input and output pins of the 8-bit timer. table 8-1. input and output pins of 8-bit timer external clock source internal clock sources clock select comparator a tcora comparator b tcorb bus interface internal data bus tcsr tcr /8 /64 /1024 tmci compare- clear clock tmo overflow tmri match a compare- match b cmia cmib ovi control logic tcnt interrupt signals tcr: tcsr: tcora: tcorb: tcnt: timer control register (8 bits) timer control status register (8 bits) time constant register a (8 bits) time constant register b (8 bits) timer counter module data bus abbreviation name tmr0 tmr1 i/o function timer output tmo 0 tmo 1 output output controlled by compare-match timer clock input tmci 0 tmci 1 input external clock source for the counter timer reset input tmri 0 tmri 1 input external reset signal for the counter 152
8.1.4 register configuration table 8-2 lists the registers of the 8-bit timer module. each channel has an independent set of registers. table 8-2. 8-bit timer registers * software can write a 0 to clear bits 7 to 5, but cannot write a 1 in these bits. 8.2 register descriptions 8.2.1 timer counter (tcnt) ?h?fc8 (tmr0), h?fd0 (tmr1) each timer counter (tcnt) is an 8-bit up-counter that increments on a pulse generated from one of four clock sources. the clock source is selected by clock select bits 2 to 0 (cks2 to cks0) of the timer control register (tcr). the cpu can always read or write the timer counter. the timer counter can be cleared by an external reset input or by an internal compare-match signal generated at a compare-match event. counter clear bits 1 and 0 (cclr1 and cclr0) of the timer control register select the method of clearing. when a timer counter overflows from h?f to h?0, the overflow flag (ovf) in the timer control/status register (tcsr) is set to 1. the timer counters are initialized to h?0 at a reset and in the standby modes. address name abbreviation r/w initial value tmr0 tmr1 timer control register tcr r/w h?0 h?fc8 h?fd0 timer control/status register tcsr r/(w)* h?0 h?fc9 h?fd1 timer constant register a tcora r/w h?f h?fca h?fd2 timer constant register b tcorb r/w h?f h?fcb h?fd3 timer counter tcnt r/w h?0 h?fcc h?fd4 bit 7 6 5 4 3 2 1 0 initial value 0 0 0 0 0 0 0 0 read/write r/w r/w r/w r/w r/w r/w r/w r/w 153
8.2.2 time constant registers a and b (tcora and tcorb) ?h?fca and h?fcb (tmr0), h?fd2 and h?fd3 (tmr1) tcora and tcorb are 8-bit readable/writable registers. the timer count is continually compared with the constants written in these registers. when a match is detected, the corresponding compare-match flag (cmfa or cmfb) is set in the timer control/status register (tcsr). the timer output signal (tmo0 or tmo1) is controlled by these compare-match signals as specified by output select bits 3 to 0 (os3 to os0) in the timer control/status register (tcsr). tcora and tcorb are initialized to h?f at a reset and in the standby modes. compare-match is not detected during the t 3 state of a write cycle to tcora or tcorb. see item (3) in section 8.6, application notes. bit 7 6 5 4 3 2 1 0 initial value 1 1 1 1 1 1 1 1 read/write r/w r/w r/w r/w r/w r/w r/w r/w bit 7 6 5 4 3 2 1 0 cmieb cmiea ovie cclr1 cclr0 cks2 cks1 cks0 initial value 0 0 0 0 0 0 0 0 read/write r/w r/w r/w r/w r/w r/w r/w r/w 154 tcr is an 8-bit readable/writable register that selects the clock source and the time at which the timer counter is cleared, and enables interrupts. tcr is initialized to h?0 at a reset and in the standby modes. bit 7 ?compare-match interrupt enable b (cmieb): this bit selects whether to request compare-match interrupt b (cmib) when compare-match flag b (cmfb) in the timer control/status register (tcsr) is set to 1. 8.2.3 timer control register (tcr) ?h?fc8 (tmr0), h?fd0 (tmr1)
bit 6 ?compare-match interrupt enable a (cmiea): this bit selects whether to request compare-match interrupt a (cmia) when compare-match flag a (cmfa) in the timer control/status register (tcsr) is set to 1. bit 5 ?timer overflow interrupt enable (ovie): this bit selects whether to request a timer overflow interrupt (ovi) when the overflow flag (ovf) in the timer control/status register (tcsr) is set to 1. bits 4 and 3 ?counter clear 1 and 0 (cclr1 and cclr0): these bits select how the timer counter is cleared: by compare-match a or b or by an external reset input. bits 2, 1, and 0 ?clock select (cks2, cks1, and cks0): these bits select the internal or external clock source for the timer counter. for the external clock source they select whether to increment the count on the rising or falling edge of the clock input, or on both edges. for the internal clock sources the count is incremented on the falling edge of the clock input. bit 7 cmieb description 0 compare-match interrupt request b (cmib) is disabled. (initial value) 1 compare-match interrupt request b (cmib) is enabled. bit 6 cmiea description 0 compare-match interrupt request a (cmia) is disabled. (initial value) 1 compare-match interrupt request a (cmia) is enabled. bit 5 ovie description 0 the timer overflow interrupt request (ovi) is disabled. (initial value) 1 the timer overflow interrupt request (ovi) is enabled. bit 4 bit 3 cclr1 cclr0 description 0 0 not cleared. (initial value) 0 1 cleared on compare-match a. 1 0 cleared on compare-match b. 1 1 cleared on rising edge of external reset input signal. 155
8.2.4 timer control/status register (tcsr) ?h?fc9 (tmr0), h?fd1 (tmr1) * software can write a 0 in bits 7 to 5 to clear the flags, but cannot write a 1 in these bits. tcsr is an 8-bit readable and partially writable register that indicates compare-match and overflow status and selects the effect of compare-match events on the timer output signal. tcsr is initialized to h?0 at a reset and in the standby modes. bit 7 ?compare-match flag b (cmfb): this status flag is set to 1 when the timer count matches the time constant set in tcorb. cmfb must be cleared by software. it is set by hardware, however, and cannot be set by software. bit 6 ?compare-match flag a (cmfa): this status flag is set to 1 when the timer count matches the time constant set in tcora. cmfa must be cleared by software. it is set by hardware, however, and cannot be set by software. bit 2 bit 1 bit 0 cks2 cks1 cks0 description 0 0 0 no clock source (timer stopped) (initial value) 0 0 1 /8 internal clock source, counted on the falling edge 0 1 0 /64 internal clock source, counted on the falling edge 0 1 1 /1024 internal clock source, counted on the falling edge 1 0 0 no clock source (timer stopped) 1 0 1 external clock source, counted on the rising edge 1 1 0 external clock source, counted on the falling edge 1 1 1 external clock source, counted on both the rising and falling edges bit 7 6 5 4 3 2 1 0 cmfb cmfa ovf os3 os2 os1 os0 initial value 0 0 0 1 0 0 0 0 read/write r/(w)* r/(w)* r/(w)* r/w r/w r/w r/w bit 7 cmfb description 0 to clear cmfb, the cpu must read cmfb after (initial value) it has been set to 1, then write a 0 in this bit. 1 this bit is set to 1 when tcnt = tcorb. 156
bit 5 ?timer overflow flag (ovf): this status flag is set to 1 when the timer count overflows (changes from h?f to h?0). ovf must be cleared by software. it is set by hardware, however, and cannot be set by software. bit 4 ?reserved: this bit is always read as 1. it cannot be written. bits 3 to 0 ?output select 3 to 0 (os3 to os0): these bits specify the effect of compare-match events on the timer output signal. bits os3 and os2 control the effect of compare-match b on the output level. bits os1 and os0 control the effect of compare-match a on the output level. if compare-match a and b occur simultaneously, any conflict is resolved by giving highest priority to toggle, second-highest priority to 1 output, and third-highest priority to 0 output, as explained in item (4) in section 8.6, application notes. after a reset, the timer output is 0 until the first compare-match event. when all four output select bits are cleared to 0 the timer output signal is disabled. bit 6 cmfa description 0 to clear cmfa, the cpu must read cmfa after (initial value) it has been set to 1, then write a 0 in this bit. 1 this bit is set to 1 when tcnt = tcora. bit 5 ovf description 0 to clear ovf, the cpu must read ovf after (initial value) it has been set to 1, then write a 0 in this bit. 1 this bit is set to 1 when tcnt changes from h?f to h?0. bit 3 bit 2 os3 os2 description 0 0 no change when compare-match b occurs. (initial value) 0 1 output changes to 0 when compare-match b occurs. 1 0 output changes to 1 when compare-match b occurs. 1 1 output inverts (toggles) when compare-match b occurs. 157
8.3 operation 8.3.1 tcnt incrementation timing the timer counter increments on a pulse generated once for each period of the clock source selected by bits cks2 to cks0 of the tcr. internal clock: internal clock sources are created from the system clock by a prescaler. the counter increments on an internal tcnt clock pulse generated from the falling edge of the prescaler output, as shown in figure 8-2. bits cks2 to cks0 of the tcr can select one of the three internal clocks (/8, /64, or /1024). figure 8-2. count timing for internal clock input external clock: if external clock input (tmci) is selected, the timer counter can increment on the rising edge, the falling edge, or both edges of the external clock signal. figure 8-3 shows incrementation on both edges of the external clock signal. the external clock pulse width must be at least 1.5 system clock periods for incrementation on a single edge, and at least 2.5 system clock periods for incrementation on both edges. see figure 8.4. the counter will not increment correctly if the pulse width is shorter than these values. bit 1 bit 0 os1 os0 description 0 0 no change when compare-match a occurs. (initial value) 0 1 output changes to 0 when compare-match a occurs. 1 0 output changes to 1 when compare-match a occurs. 1 1 output inverts (toggles) when compare-match a occurs. figure 8-2 internal clock tcnt clock pulse tcnt n? n n+1 158
figure 8-3. count timing for external clock input figure 8-4. minimum external clock pulse widths (example) 8.3.2 compare match timing (1) setting of compare-match flags a and b (cmfa and cmfb): the compare-match flags are set to 1 by an internal compare-match signal generated when the timer count matches the time constant in tcnt or tcor. the compare-match signal is generated at the last state in which the match is true, just before the timer counter increments to a new value. external clock source tcnt clock pulse tcnt n n + 1 n ?1 tmci tmci minimum tmci pulse width (single-edge incrementation) minimum tmci pulse width (double-edge incrementation) 159
accordingly, when the timer count matches one of the time constants, the compare-match signal is not generated until the next period of the clock source. figure 8-5 shows the timing of the setting of the compare-match flags. figure 8-5. setting of compare-match flags (2) timing of compare-match flag (cmfa or cmfb) clearing: the compare-match flag cmfa or cmfb is cleared when the cpu writes a 0 in this bit. figure 8-6. clearing of compare-match flags (3) output timing: when a compare-match event occurs, the timer output (tmo0 or tmo1) changes as specified by the output select bits (os3 to os0) in the tcsr. depending on these bits, the output can remain the same, change to 0, change to 1, or toggle. if compare-match a and b occur simultaneously, the higher priority compare-match determines the output level. see item (4) in section 8.6, application notes for details. f tcnt tcor internal compare-match signal cmf n n + 1 n write cycle: cpu writes 0 in cmfa or cmfb t 1 t 2 t 3 cmfa or cmfb fig 8-6 160
figure 8-7 shows the timing when the output is set to toggle on compare-match a. figure 8-7. timing of timer output (4) timing of compare-match clear: depending on the cclr1 and cclr0 bits in the tcr, the timer counter can be cleared when compare-match a or b occurs. figure 8-8 shows the timing of this operation. figure 8-8. timing of compare-match clear 8.3.3 external reset of tcnt when the cclr1 and cclr0 bits in the tcr are both set to 1, the timer counter is cleared on the rising edge of an external reset input. figure 8-9 shows the timing of this operation. the timer reset pulse width must be at least 1.5 system clock periods. internal compare-match a signal timer output (tmo) n h?0 internal compare-match signal tcnt 161
figure 8-9. timing of external reset 8.3.4 setting of tcsr overflow flag (1) setting of tcsr overflow flag (ovf): the overflow flag (ovf) is set to 1 when the timer count overflows (changes from h?f to h?0). figure 8-10 shows the timing of this operation. figure 8-10. setting of overflow flag (ovf) (2) timing of tcsr overflow flag (ovf) clearing: the overflow flag (ovf) is cleared when the cpu writes a 0 in this bit. external reset input (tmri) internal clear pulse tcnt n n ?1 h?0 h?0 tcnt internal overflow signal ovf h?f 162
figure 8-11. clearing of overflow flag 8.4 interrupts each channel in the 8-bit timer can generate three types of interrupts: compare-match a and b (cmia and cmib), and overflow (ovi). each interrupt is requested when the corresponding enable bits are set in the tcr and tcsr. independent signals are sent to the interrupt controller for each interrupt. table 8-3 lists information about these interrupts. table 8-3. 8-bit timer interrupts 8.5 sample application in the example below, the 8-bit timer is used to generate a pulse output with a selected duty factor. the control bits are set as follows: (1) in the tcr, cclr1 is cleared to 0 and cclr0 is set to 1 so that the timer counter is cleared when its value matches the constant in tcora. (2) in the tcsr, bits os3 to os0 are set to 0110, causing the output to change to 1 on compare- match a and to 0 on compare-match b. with these settings, the 8-bit timer provides output of pulses at a rate determined by tcora with a pulse width determined by tcorb. no software intervention is required. when cycle: cpu writes "0" in ovf t 1 t 2 t 3 ovf interrupt description priority cmia requested when cmfa and cmiea are set high cmib requested when cmfb and cmieb are set ovi requested when ovf and ovie are set low 163
figure 8-12. example of pulse output 8.6 application notes application programmers should note that the following types of contention can occur in the 8-bit timer. (1) contention between tcnt write and clear: if an internal counter clear signal is generated during the t 3 state of a write cycle to the timer counter, the clear signal takes priority and the write is not performed. figure 8-13 shows this type of contention. figure 8-13. tcnt write-clear contention h?f tcora tcorb h?0 tmo pin clear counter tcnt internal address bus internal write signal counter clear signal tcnt n h?0 tcnt address write cycle: cpu writes to tcnt t 1 t 2 t 3 figure 7-13 164
(2) contention between tcnt write and increment: if a timer counter increment pulse is generated during the t 3 state of a write cycle to the timer counter, the write takes priority and the timer counter is not incremented. figure 8-14 shows this type of contention. figure 8-14. tcnt write-increment contention (3) contention between tcor write and compare-match: if a compare-match occurs during the t 3 state of a write cycle to tcora or tcorb, the write takes precedence and the compare- match signal is inhibited. figure 8-15 shows this type of contention. internal address bus internal write signal tcnt clock pulse tcnt n m tcnt address write cycle: cpu writes to tcnt t 1 write data t 2 t 3 figure 7-14 165
figure 8-15. contention between tcor write and compare-match (4) contention between compare-match a and compare-match b: if identical time constants are written in tcora and tcorb, causing compare-match a and b to occur simultaneously, any conflict between the output selections for compare-match a and b is resolved by following the priority order in table 8-4. table 8-4. priority of timer output (5) incrementation caused by changing of internal clock source: when an internal clock source is changed, the changeover may cause the timer counter to increment. this depends on the time at which the clock select bits (cks2 to cks0) are rewritten, as shown in table 8-5. internal address bus internal write signal tcnt n m tcor address write cycle: cpu writes to tcora or tcorb n n + 1 tcora or tcorb compare-match a or b signal t 1 inhibited tcor write data figure 7-15 t 2 t 3 output selection priority toggle high 1 output 0 output no change low 166
the pulse that increments the timer counter is generated at the falling edge of the internal clock source signal. if clock sources are changed when the old source is high and the new source is low, as in case no. 3 in table 8-5, the changeover generates a falling edge that triggers the tcnt clock pulse and increments the timer counter. switching between an internal and external clock source can also cause the timer counter to increment. this type of switching should be avoided at external clock edges. table 8-5. effect of changing internal clock sources * 1 including a transition from low to the stopped state (cks1 = 0, cks0 = 0), or a transition from the stopped state to low. * 2 including a transition from the stopped state to high. no. description timing chart low ? low* 1 : cks1 and cks0 are 1 rewritten while both clock sources are low. low ? high* 2 : cks1 and cks0 are 2 rewritten while old clock source is low and new clock source is high. n + 1 n old clock source new clock source tcnt clock pulse tcnt cks rewrite n + 1 n old clock source new clock source tcnt clock pulse tcnt cks rewrite n + 2 167
table 8-5. effect of changing internal clock sources (cont.) * 1 including a transition from high to the stopped state. * 2 the switching of clock sources is regarded as a falling edge that increments the tcnt. no. description timing chart high ? low* 1 : cks1 and cks0 are 3 rewritten while old clock source is high and new clock source is low. high ? high: cks1 and cks0 are 4 rewritten while both clock sources are high. old clock source new clock source tcnt clock pulse tcnt cks rewrite n n + 1 n + 2 * 3 *2 n + 1 n old clock source new clock source tcnt clock pulse tcnt cks rewrite n + 2 168
section 9. serial communication interface 9.1 overview the h8/325 series chips include a serial communication interface module (sci) with two channels for transferring serial data to and from other chips. either synchronous or asynchronous communication can be selected. communication control functions are provided by internal registers. 9.1.1 features the features of the on-chip serial communication interface are: asynchronous and synchronous modes asynchronous mode the sci can communicate with a uart (universal asynchronous receiver/transmitter), acia (asynchronous communication interface adapter), or other chip that employs standard asynchronous serial communication. eight data formats are available. data length: 7 or 8 bits stop bit length: 1 or 2 bits parity: even, odd, or none error detection: parity, overrun, and framing errors synchronous mode the sci can communicate with chips able to perform clocked serial data transfer. data length: 8 bits error detection: overrun errors full duplex communication the transmitting and receiving sections are independent, so the sci can transmit and receive simultaneously. both the transmit and receive sections use double buffering, so continuous data transfer is possible in either direction. built-in baud rate generator any specified baud rate can be generated. internal or external clock source the baud rate generator can operate on an internal clock source, or an external clock signal can be input at the sck pin. three interrupts transmit-end, receive-end, and receive-error interrupts are requested independently. 169
9.1.2 block diagram figure 9-1. block diagram of serial communication interface 9.1.3 input and output pins table 9-1 lists the input and output pins used by the sci module. table 9-1. sci input/output pins abbreviation name channel 0 channel 1 i/o function serial clock sck 0 sck 1 input/output serial clock input and output. serial receive data rxd 0 rxd 1 input receive data input. serial transmit data txd 0 txd 1 output transmit data output. tdr bus interface internal data bus module data bus parity generate clock parity check tsr /4 /16 /64 rxd txi rxi eri interrupt signals external clock source internal clock sources rdr rsr brr communi- cation control ssr scr smr baud rate generator rsr: rdr: tsr: tdr: smr: scr: ssr: brr: receive shift register receive data register transmit shift register transmit data register serial mode register serial control register serial status register bit rate register figure 9-1 txd sck 170
9.1.4 register configuration table 9-2 lists the sci registers. table 9-2. sci registers notes: * software can write a 0 to clear the status flag bits, but cannot write a 1. 9.2 register descriptions 9.2.1 receive shift register (rsr) the rsr receives incoming data bits. when one data character (1 byte) has been received, it is transferred to the receive data register (rdr). the cpu cannot read or write the rsr directly channel name abbreviation r/w initial value address 0 receive shift register rsr receive data register rdr r h?0 h?fdd transmit shift register tsr transmit data register tdr r/w h?f h?fdb serial mode register smr r/w h?4 h?fd8 serial control register scr r/w h?c h?fda serial status register ssr r/(w)* h?7 h?fdc bit rate register brr r/w h?f h?fd9 1 receive shift register rsr receive data register rdr r h?0 h?fe5 transmit shift register tsr transmit data register tdr r/w h?f h?fe3 serial mode register smr r/w h?4 h?fe0 serial control register scr r/w h?c h?fe2 serial status register ssr r/(w)* h?7 h?fe4 bit rate register brr r/w h?f h?fe1 bit 7 6 5 4 3 2 1 0 read/write 171
9.2.2 receive data register (rdr) ?h?fdd the rdr stores received data. as each character is received, it is transferred from the rsr to the rdr, enabling the rsr to receive the next character. this double-buffering allows the sci to receive data continuously. the cpu can read but not write the rdr. the rdr is initialized to h?0 at a reset and in the standby modes. 9.2.3 transmit shift register (tsr) the tsr holds the character currently being transmitted. when transmission of this character is completed, the next character is moved from the transmit data register (tdr) to the tsr and transmission of that character begins. if the cpu has not written the next character in the tdr, no data are transmitted. the cpu cannot read or write the tsr directly. 9.2.4 transmit data register (tdr) ?h?fdb the tdr is an 8-bit readable/writable register that holds the next character to be transmitted. when the tsr becomes empty, the character written in the tdr is transferred to the tsr. continuous data transmission is possible by writing the next byte in the tdr while the current byte is being transmitted from the tsr. the tdr is initialized to h?f at a reset and in the standby modes. bit 7 6 5 4 3 2 1 0 initial value 0 0 0 0 0 0 0 0 read/write r r r r r r r r bit 7 6 5 4 3 2 1 0 read/write bit 7 6 5 4 3 2 1 0 initial value 1 1 1 1 1 1 1 1 read/write r/w r/w r/w r/w r/w r/w r/w r/w 172
9.2.5 serial mode register (smr) ?h?fd8 the smr is an 8-bit readable/writable register that controls the communication format and selects the clock rate for the internal clock source. it is initialized to h?4 at a reset and in the standby modes. for further information on communication formats, see tables 9-5 and 9-7 section 9.3, operation. bit 7 ?communication mode (c/a): this bit selects the asynchronous or synchronous communication mode. bit 6 ?character length (chr): this bit selects the character length in asynchronous mode. it is ignored in synchronous mode. bit 5 ?parity enable (pe): this bit selects whether to add a parity bit in asynchronous mode. it is ignored in synchronous mode. bit 7 6 5 4 3 2 1 0 c/a chr pe o/e stop cks1 cks0 initial value 0 0 0 0 0 1 0 0 read/write r/w r/w r/w r/w r/w r/w r/w bit 7 c/a description 0 asynchronous communication. (initial value) 1 clock-synchronized communication. bit 6 chr description 0 8 bits per character. (initial value) 1 7 bits per character. bit 5 pe description 0 transmit: no parity bit is added. (initial value) receive: parity is not checked. 1 transmit: a parity bit is added. receive: parity is checked. 173
bit 4 ?parity mode (o/e ): in asynchronous mode, when parity is enabled (pe = 1), this bit selects even or odd parity. even parity means that a parity bit is added to the data bits for each character to make the total number of 1s even. odd parity means that the total number of 1s is made odd. this bit is ignored when pe = 0, and in the synchronous mode. bit 3 ?stop bit length (stop): this bit selects the number of stop bits. it is ignored in the synchronous mode. bit 2 ?reserved: this bit cannot be modified and is always read as 1. bits 1 and 0 ?clock select 1 and 0 (cks1 and cks0): these bits select the internal clock source when the baud rate generator is clocked internally. for further information about smr settings, see tables 9-5 to 9-7 in section 9.3, operation. bit 4 o/e description 0 even parity. (initial value) 1 odd parity. bit 3 stop description 0 1 stop bit. (initial value) 1 2 stop bits. bit 1 bit 0 cks1 cks0 description 0 0 clock (initial value) 0 1 /4 clock 1 0 /16 clock 1 1 /64 clock 174
9.2.6 serial control register (scr) ?h?fda the scr is an 8-bit readable/writable register that enables or disables various sci functions. it is initialized to h?c at a reset and in the standby modes. bit 7 ?transmit interrupt enable (tie): this bit enables or disables the transmit-end interrupt (txi) requested when the transmit data register empty (tdre) bit in the serial status register (ssr) is set to 1. bit 6 ?receive interrupt enable (rie): this bit enables or disables the receive-end interrupt (rxi) requested when the receive data register full (rdrf) bit in the serial status register (ssr) is set to 1, and the receive error interrupt (eri) requested when the overrun error bit (orer), framing error bit (fer), or parity error bit (per) is set to 1. bit 5 ?transmit enable (te): this bit enables or disables the transmit function. when the transmit function is enabled, the txd pin is automatically used for output. when the transmit function is disabled, the txd pin can be used as a general-purpose i/o port. bit 7 6 5 4 3 2 1 0 tie rie te re cke1 cke0 initial value 0 0 0 0 1 1 0 0 read/write r/w r/w r/w r/w r/w r/w bit 7 tie description 0 the transmit-end interrupt request (txi) is disabled. (initial value) 1 the transmit-end interrupt request (txi) is enabled. bit 6 rie description 0 the receive-end interrupt (rxi) request is disabled. (initial value) 1 the receive-end interrupt (rxi) request is enabled. bit 5 te description 0 the transmit function is disabled. (initial value) the txd pin can be used for general-purpose i/o. 1 the transmit function is enabled. the txd pin is used for output. 175
bit 4 ?receive enable (re): this bit enables or disables the receive function. when the receive function is enabled, the rxd pin is automatically used for input. when the receive function is disabled, the rxd pin is available as a general-purpose i/o port. bits 3 and 2 ?reserved: these bits cannot be modified and are always read as 1. bit 1 ?clock enable 1 (cke1): this bit selects the internal or external clock source for the baud rate generator. when the external clock source is selected, the sck pin is automatically used for input of the external clock signal. bit 0 ?clock enable 0 (cke0): when an internal clock source is used in asynchronous mode, this bit enables or disables serial clock output at the sck pin. this bit is ignored when the external clock is selected, or when the synchronous mode is selected. for further information on clock source selection, see table 9-6 in section 9.3, operation. bit 4 re description 0 the receive function is disabled. the rxd pin can be (initial value) used for general-purpose i/o. 1 the receive function is enabled. the rxd pin is used for input. bit 1 cke1 description 0 internal clock source. (initial value) when c/a = 1, the clock is output at sck. when c/a = 0, clock output depends on cke0. 1 external clock source, input at sck. bit 0 cke0 description 0 the sck pin is not used by the sci (and is available as (initial value) a general-purpose i/o port). 1 the sck pin is used for serial clock output. 176
9.2.7 serial status register (ssr) ?h?fdc * software can write a 0 to clear the flags, but cannot write a 1 in these bits. the ssr is an 8-bit register that indicates transmit and receive status. it is initialized to h?7 at a reset and in the standby modes. bit 7 ?transmit data register empty (tdre): this bit indicates when the tdr contents have been transferred to the tsr and the next character can safely be written in the tdr. bit 6 ?receive data register full (rdrf): this bit indicates when one character has been received and transferred to the rdr. bit 7 6 5 4 3 2 1 0 tdre rdrf orer fer per initial value 1 0 0 0 0 1 1 1 read/write r/(w)* r/(w)* r/(w)* r/(w)* r/(w)* bit 7 tdre description 0 to clear tdre, the cpu must read tdre after it has been set to 1, then write a 0 in this bit. 1 this bit is set to 1 at the following times: (initial value) (1) when tdr contents are transferred to the tsr. (2) when the te bit in the scr is cleared to 0. bit 6 rdrf description 0 to clear rdrf, the cpu must read rdrf after (initial value) it has been set to 1, then write a 0 in this bit. 1 this bit is set to 1 when one character is received without error and transferred from the rsr to the rdr. 177
bit 5 ?overrun error (orer): this bit indicates an overrun error during reception. bit 4 ?framing error (fer): this bit indicates a framing error during data reception in asyn- chronous mode. it has no meaning in synchronous mode. bit 3 ?parity error (per): this bit indicates a parity error during data reception in asynchro- nous mode, when a communication format with parity bits is used. this bit has no meaning in synchronous mode, or when a communication format without parity bits is used. bits 2 to 0 ?reserved: these bits cannot be modified and are always read as 1. bit 5 orer description 0 to clear orer, the cpu must read orer after (initial value) it has been set to 1, then write a 0 in this bit. 1 this bit is set to 1 if reception of the next character ends while the receive data register is still full (rdrf = 1). bit 4 fer description 0 to clear fer, the cpu must read fer after (initial value) it has been set to 1, then write a 0 in this bit. 1 this bit is set to 1 if a framing error occurs (stop bit = 0). bit 3 per description 0 to clear per, the cpu must read per after (initial value) it has been set to 1, then write a 0 in this bit. 1 this bit is set to 1 when a parity error occurs (the parity of the received data does not match the parity selected by the o/e bit in the smr). 178
9.2.8 bit rate register (brr) ?h?fd9 the brr is an 8-bit register that, together with the cks1 and cks0 bits in the smr, determines the baud rate output by the baud rate generator. the brr is initialized to h?f (the slowest rate) at a reset and in the standby modes. tables 9-3 and 9-4 show examples of brr (n) and cks (n) settings for commonly used bit rates. table 9-3. examples of brr settings in asynchronous mode (1) bit 7 6 5 4 3 2 1 0 initial value 1 1 1 1 1 1 1 1 read/write r/w r/w r/w r/w r/w r/w r/w r/w xtal frequency (mhz) 2 2.4576 4 4.194304 bit error error error error rate n n (%) n n (%) n n (%) n n (%) 110 1 70 +0.03 1 86 +0.31 1 141 +0.03 1 148 ?.04 150 0 207 +0.16 0 255 0 1 103 +0.16 1 108 +0.21 300 0 103 +0.16 0 127 0 0 207 +0.16 0 217 +0.21 600 0 51 +0.16 0 63 0 0 103 +0.16 0 108 +0.21 1200 0 25 +0.16 0 31 0 0 51 +0.16 0 54 ?.70 2400 0 12 +0.16 0 15 0 0 25 +0.16 0 26 +1.14 4800 0 7 0 0 12 +0.16 0 13 ?.48 9600 0 3 0 19200 0 1 0 31250 0 1 0 38400 0 0 0 179
table 9-3. examples of brr settings in asynchronous mode (2) table 9-3. examples of brr settings in asynchronous mode (3) xtal frequency (mhz) 4.9152 6 7.3728 8 bit error error error error rate n n (%) n n (%) n n (%) n n (%) 110 1 174 ?.26 2 52 +0.50 2 64 +0.70 2 70 +0.03 150 1 127 0 1 155 +0.16 1 191 0 1 207 +0.16 300 0 255 0 1 77 +0.16 1 95 0 1 103 +0.16 600 0 127 0 0 155 +0.16 0 191 0 0 207 +0.16 1200 0 63 0 0 77 +0.16 0 95 0 0 103 +0.16 2400 0 31 0 0 38 +0.16 0 47 0 0 51 +0.16 4800 0 15 0 0 19 ?.34 0 23 0 0 25 +0.16 9600 0 7 0 0 11 0 0 12 +0.16 19200 0 3 0 0 5 0 31250 0 2 0 0 3 0 38400 0 1 0 0 2 0 xtal frequency (mhz) 9.8304 10 12 12.288 bit error error error error rate n n (%) n n (%) n n (%) n n (%) 110 2 86 +0.31 2 88 ?.25 2 106 ?.44 2 108 +0.08 150 1 255 0 2 64 +0.16 2 77 0 2 79 0 300 1 127 0 1 129 +0.16 1 155 0 1 159 0 600 0 255 0 1 64 +0.16 1 77 0 1 79 0 1200 0 127 0 0 129 +0.16 0 155 +0.16 0 159 0 2400 0 63 0 0 64 +0.16 0 77 +0.16 0 79 0 4800 0 31 0 0 32 ?.36 0 38 +0.16 0 39 0 9600 0 15 0 0 15 +1.73 0 19 ?.34 0 19 0 19200 0 7 0 0 7 +1.73 0 4 0 31250 0 4 ?.70 0 4 0 0 5 0 0 5 +2.40 38400 0 3 0 0 3 +1.73 180
table 9-3. examples of brr settings in asynchronous mode (4) note: if possible, the error should be within 1%. b = osc ? 10 6 /[64 ? 2 2n ? (n + 1)] n : brr value (0 n 255) osc : crystal oscillator frequency in mhz b : bit rate (bits/second) n : internal clock source (0, 1, 2, or 3) the meaning of n is given by the table below: xtal frequency (mhz) 14.7456 16 19.6608 20 bit error error error error rate n n (%) n n (%) n n (%) n n (%) 110 2 130 ?.07 2 141 +0.03 2 174 ?.26 3 43 +0.88 150 2 95 0 2 103 +0.16 2 127 0 2 129 +0.16 300 1 191 0 1 207 +0.16 1 255 0 2 64 +0.16 600 1 95 0 1 103 +0.16 1 127 0 1 129 +0.16 1200 0 191 0 0 207 +0.16 0 255 0 1 64 +0.16 2400 0 95 0 0 103 +0.16 0 127 0 0 129 +0.16 4800 0 47 0 0 51 +0.16 0 63 0 0 64 +0.16 9600 0 23 0 0 25 +0.16 0 31 0 0 32 ?.36 19200 0 11 0 0 12 +0.16 0 15 0 0 15 +1.73 31250 0 7 0 0 9 ?.70 0 9 0 38400 0 5 0 0 7 0 0 7 +1.73 n cks1 cks0 clock 0 0 0 1 0 1 /4 2 1 0 /16 3 1 1 /64 181
table 9-4. examples of brr settings in synchronous mode notes: blank: no setting is available. ? a setting is available, but the bit rate is inaccurate. *: continuous transfer is not possible. b = osc ? 10 6 /[8 ? 2 2n ? (n + 1)] n : brr value (0 n 255) osc : crystal oscillator frequency in mhz b : bit rate (bits per second) n : internal clock source (0, 1, 2, or 3) the meaning of n is given by the table below: xtal frequency (mhz) bit 2 4 8 10 16 20 rate n n n n n n n n n n n n 100 250 1 249 2 124 2 249 3 124 500 1 124 1 249 2 124 2 249 1k 0 249 1 124 1 249 2 124 2.5k 0 99 0 199 1 99 1 124 1 199 1 249 5k 0 49 0 99 0 199 0 249 1 99 1 124 10k 0 24 0 49 0 99 0 124 0 199 0 249 25k 0 9 0 19 0 39 0 49 0 79 0 99 50k 0 4 0 9 0 19 0 24 0 39 0 49 100k 0 4 0 9 0 19 0 24 250k 0 0* 0 1 0 3 0 4 0 7 0 9 500k 0 0* 0 1 0 3 0 4 1m 0 0* 0 1 2.5m 0 0* n cks1 cks0 clock 0 0 0 1 0 1 /4 2 1 0 /16 3 1 1 /64 182
9.3 operation 9.3.1 overview the sci supports serial data transfer in both asynchronous and synchronous modes. the communication format depends on settings in the smr as indicated in table 9-5. the clock source and usage of the sck pin depend on settings in the smr and scr as indicated in table 9-6. table 9-5. communication formats used by sci table 9-6. sci clock source selection * not used by the sci. smr stop bit c/a chr pe stop mode format parity length 0 0 0 0 none 1 1 8-bit data 2 1 0 yes 1 1 asynchronous 2 1 0 0 none 1 1 7-bit data 2 1 0 yes 1 1 2 1 synchronous 8-bit data smr scr clock c/a cke1 cke0 source sck pin 0 0 0 internal input/output port* (async 1 serial clock output mode) at bit rate 1 0 external serial clock input 1 at 16 bit rate 1 0 0 internal serial clock output (sync 1 mode) 1 0 external serial clock input 1 183
transmitting and receiving operations in the two modes are described next. 9.3.2 asynchronous mode in asynchronous mode, each character is individually synchronized by framing it with a start bit and stop bit. full duplex data transfer is possible because the sci has independent transmit and receive sections. double buffering in both sections enables the sci to be programmed for continuous data transfer. figure 9-2 shows the general format of one character sent or received in the asynchronous mode. the communication channel is normally held in the mark state (high). character transmission or reception starts with a transition to the space state (low). the first bit transmitted or received is the start bit (low). it is followed by the data bits, in which the least significant bit (lsb) comes first. the data bits are followed by the parity bit, if present, then the stop bit or bits (high) confirming the end of the frame. in receiving, the sci synchronizes on the falling edge of the start bit, and samples each bit at the center of the bit (at the 8th cycle of the internal serial clock, which runs at 16 times the bit rate). figure 9-2. data format in asynchronous mode (1) data format: table 9-7 lists the data formats that can be sent and received in asynchronous mode. eight formats can be selected by bits in the smr. d0 d1 dn start bit 1 bit 7 or 8 bits one character parity bit stop bit 0 or 1 bit 1 or 2 bits idle state (mark) fig 9-2 184
table 9-7. data formats in asynchronous mode note start: start bit stop: stop bit p: parity bit (2) clock: in asynchronous mode it is possible to select either an internal clock created by the on- chip baud rate generator, or an external clock input at the sck pin. refer to table 9-6. if an external clock is input at the sck pin, its frequency should be 16 times the desired baud rate. if the internal clock provided by the on-chip baud rate generator is selected and the sck pin is used for clock output, the output clock frequency is equal to the baud rate, and the clock pulse rises at the center of the transmit data bits. figure 9-3 shows the phase relationship between the output clock and transmit data. figure 9-3. phase relationship between clock output and transmit data smr bits chr pe stop data format 0 0 0 start 8-bit data stop 0 0 1 start 8-bit data stop stop 0 1 0 start 8-bit data p stop 0 1 1 start 8-bit data p stop stop 1 0 0 start 7-bit data stop 1 0 1 start 7-bit data stop stop 1 1 0 start 7-bit data p stop 1 1 1 start 7-bit data p stop stop ...... output clock transmit data start bit d1 d2 d3 . . . . . . . . . . . . 185
(3) data transmission and reception sci initialization: before data can be transmitted or received, the sci must be initialized by software. to initialize the sci, software must clear the te and re bits to 0, then execute the following procedure. set the desired communication format in the smr. write the value corresponding to the desired baud rate in the brr. (this step is not necessary if an external clock is used.) select the clock and enable desired interrupts in the scr. set the te and/or re bit in the scr to 1. the te and re bits must both be cleared to 0 whenever the operating mode or data format is changed. after changing the operating mode or data format, before setting the te and re bits to 1 software must wait for at least the transfer time for 1 bit at the selected baud rate, to make sure the sci is initialized. if an external clock is used, the clock must not be stopped. when clearing the tdre bit during data transmission, to assure transfer of the correct data, do not clear the tdre bit until after writing data in the tdr. similarly, in receiving data, do not clear the rdrf bit until after reading data from the rdr. data transmission: the procedure for transmitting data is as follows. set up the desired transmitting conditions in the smr, scr, and brr. set the te bit in the scr to 1. the txd pin will automatically be switched to output and one frame* of all 1s will be transmitted, after which the sci is ready to transmit data. check that the tdre bit is set to 1, then write the first byte of transmit data in the tdr. next clear the tdre bit to 0. 186
? the first byte of transmit data is transferred from the tdr to the tsr and sent in the designated format as follows. i) start bit (one 0 bit). ii) transmit data (seven or eight bits, starting from bit 0) iii) parity bit (odd or even parity bit, or no parity bit) iv) stop bit (one or two consecutive 1 bits) transfer of the transmit data from the tdr to the tsr makes the tdr empty, so the tdre bit is set to 1. if the tie bit is set to 1, a transmit-end interrupt (txi) is requested. when the transmit function is enabled but the tdr is empty (tdre = 1), the output at the txd pin is held at 1 until the tdre bit is cleared to 0. * a frame is the data for one character, including the start bit and stop bit(s). data reception: the procedure for receiving data is as follows. set up the desired receiving conditions in the smr, scr, and brr. set the re bit in the scr to 1. the rxd pin is automatically be switched to input and the sci is ready to receive data. the sci synchronizes with the incoming data by detecting the start bit, and places the received bits in the rsr. at the end of the data, the sci checks that the stop bit is 1. when a complete frame has been received, the sci transfers the received data from the rsr to the rdr so that it can be read. if the character length is 7 bits, the most significant bit of the rdr is cleared to 0. at the same time, the sci sets the rdrf bit in the ssr to 1. if the rie bit is set to 1, a receive- end interrupt (rxi) is requested. the rdrf bit is cleared to 0 when software reads the ssr, then writes a 0 in the rdrf bit. the rdr is then ready to receive the next character from the rsr. when a frame is not received correctly, a receive error occurs. there are three types of receive errors, listed in table 9-8. 187
if a receive error occurs, the rdrf bit in the ssr is not set to 1. (for an overrun error, rdrf is already set to 1.) the corresponding error flag is set to 1 instead. if the rie bit in the scr is set to 1, a receive-error interrupt (eri) is requested. when a framing or parity error occurs, the rsr contents are transferred to the rdr. if an overrun error occurs, however, the rsr contents are not transferred to the rdr. if multiple receive errors occur simultaneously, all the corresponding error flags are set to 1. to clear a receive-error flag (orer, fer, or per), software must read the ssr and then write a 0 in the flag bit. table 9-8. receive errors 9.3.3 synchronous mode the synchronous mode is suited for high-speed, continuous data transfer. each bit of data is synchronized with a serial clock pulse at the sck pin. continuous data transfer is enabled by the double buffering employed in both the transmit and receive sections of the sci. full duplex communication is possible because the transmit and receive sections are independent. (1) data format: figure 9-4 shows the communication format used in the synchronous mode. the data length is 8 bits for both the transmit and receive directions. the least significant bit (lsb) is sent and received first. each bit of transmit data is output from the falling edge of the serial clock pulse to the next falling edge. received bits are latched on the rising edge of the serial clock pulse. name abbreviation description overrun error orer reception of the next frame ends while the rdrf bit is still set to 1. the rsr contents are not transferred to the rdr. framing error fer a stop bit is 0. the rsr contents are transferred to the rdr. parity error per the parity of a frame does not match the value selected by the o/e bit in the smr. the rsr contents are transferred to the rdr. 188
figure 9-4. data format in synchronous mode (2) clock: either the internal serial clock created by the on-chip baud rate generator or an external clock input at the sck pin can be selected in the synchronous mode. see table 9-6 for details. (3) data transmission and reception sci initialization: before data can be transmitted or received, the sci must be initialized by software. to initialize the sci, software must clear the te and re bits to 0 to disable both the transmit and receive functions, then execute the following procedure. write the value corresponding to the desired bit rate in the brr. (this step is not necessary if an external clock is used.) select the clock and enable desired interrupts in the scr. leave bit 0 (cke0) cleared to 0. select synchronous mode in the smr. set the te and/or re bit in the scr to 1. the te and re bits must both be cleared to 0 whenever the operating mode or data format is changed. after changing the operating mode or data format, before setting the te and re bits to 1 software must wait for at least 1 bit transfer time at the selected communication speed, to make sure the sci is initialized. don?-care don?-care data serial clock bit 0 bit 1 bit 2 bit 3 bit 4 bit 5 bit 6 bit 7 transmission direction fig 9-4 189
when clearing the tdre bit during data transmission, to assure correct data transfer, do not clear the tdre bit until after writing data in the tdr. similarly, in receiving data, do not clear the rdrf bit until after reading data from the rdr. data transmission: the procedure for transmitting data is as follows. set up the desired transmitting conditions in the smr, brr, and scr. set the te bit in the scr to 1. the txd pin will automatically be switched to output, after which the sci is ready to transmit data. check that the tdre bit is set to 1, then write the first byte of transmit data in the tdr. next clear the tdre bit to 0. the first byte of transmit data is transferred from the tdr to the tsr and sent, each bit synchronized with a clock pulse. bit 0 is sent first. transfer of the transmit data from the tdr to the tsr makes the tdr empty, so the tdre bit is set to 1. if the tie bit is set to 1, a transmit-end interrupt (txi) is requested. the tdr and tsr function as a double buffer. continuous data transmission can be achieved by writing the next transmit data in the tdr and clearing the tdre bit to 0 while the sci is transmitting the current data from the tsr. if an internal clock source is selected, after transferring the transmit data from the tdr to the tsr, while transmitting the data from the tsr the sci also outputs a serial clock signal at the sck pin. when all data bits in the tsr have been transmitted, if the tdr is empty (tdre = 1), serial clock output is suspended until the next data byte is written in the tdr and the tdre bit is cleared to 0. during this interval the txd pin continues to output the value of the last bit of the previous data. if the external clock source is selected, data transmission is synchronized with the clock signal input at the sck pin. when all data bits in the tsr have been transmitted, if the tdr is empty (tdre = 1) but external clock pulses continue to arrive, the txd pin outputs the value of last bit of the previous data. data reception: the procedure for receiving data is as follows. 190
set up the desired receiving conditions in the smr, brr, and scr. set the re bit in the scr to 1. the rxd pin is automatically be switched to input and the sci is ready to receive data. incoming data bits are latched in the rsr on eight clock pulses. when 8 bits of data have been received, the sci sets the rdrf bit in the ssr to 1. if the rie bit is set to 1, a receive-end interrupt (rxi) is requested. the sci transfers the received data byte from the rsr to the rdr so that it can be read. the rdrf bit is cleared when software reads the rdrf bit in the ssr, then writes a 0 in the rdrf bit. the rdr and rsr function as a double buffer. data can be received continuously by reading each byte of data from the rdr and clearing the rdrf bit to 0 before the last bit of the next byte is received. in general, an external clock source should be used for receiving data. if an internal clock source is selected, the sci starts receiving data as soon as the re bit is set to 1. the serial clock is also output at the sck pin. the sci continues receiving until the re bit is cleared to 0. if the last bit of the next data byte is received while the rdrf bit is still set to 1, an overrun error occurs and the orer bit is set to 1. if the rie bit is set to 1, a receive-error interrupt (eri) is requested. the data received in the rsr are not transferred to the rdr when an overrun error occurs. after an overrun error, reception of the next data is enabled when the orer bit is cleared to 0. simultaneous transmit and receive: the procedure for transmitting and receiving simultaneously is as follows: set up the desired communication conditions in the smr, brr, and scr. set the te and re bits in the scr to 1. the txd and rxd pins are automatically switched to output and input, respectively, and the sci is ready to transmit and receive data. 191
a data transmitting and receiving start when the tdre bit in the ssr is cleared to 0. data are sent and received in synchronization with eight clock pulses. first, the transmit data are transferred from the tdr to the tsr. this makes the tdr empty, so the tdre bit is set to 1. if the tie bit is set to 1, a transmit-end interrupt (txi) is requested. if continuous data transmission is desired, software must read the tdre bit in the ssr, write the next transmit data in the tdr, then clear the tdre bit to 0. if the tdre bit is not cleared to 0 by the time the sci finishes sending the current byte from the tsr, the txd pin continues to output the value of last bit of the previous data. in the receiving section, when 8 bits of data have been received they are transferred from the rsr to the rdr and the rdrf bit in the ssr is set to 1. if the rie bit is set to 1, a receive- end interrupt (rxi) is requested. to clear the rdrf bit software should read the rdrf bit in the ssr, read the data in the rdr, then write a 0 in the rdrf bit. for continuous data reception, software should clear the rdrf bit to 0 before reception of the next 8 bits is completed. if the last bit of the next byte is received while the rdrf bit is still set to 1, an overrun error occurs. the error is handled as described under ?ata reception?above. the overrun error does not affect the transmit section of the sci, which continues to transmit normally. 9.4 interrupts the sci can request three types of interrupts: transmit-end (txi), receive-end (rxi), and receive- error (eri). interrupt requests are enabled or disabled by the tie and rie bits in the scr. independent signals are sent to the interrupt controller for each type of interrupt. the transmit-end and receive-end interrupt request signals are obtained from the tdre and rdrf flags. the receive-error interrupt request signal is the logical or of the three error flags: overrun error (orer), framing error (fer), and parity error (per). table 9-9 lists information about these interrupts. 192
table 9-9. sci interrupts 9.5 application notes application programmers should note the following features of the sci. (1) tdr write: the tdre bit in the ssr is simply a flag that indicates that the tdr contents have been transferred to the tsr. the tdr contents can be rewritten regardless of the tdre value. if a new byte is written in the tdr while the tdre bit is 0, before the old tdr contents have been moved into the tsr, the old byte will be lost. normally, software should check that the tdre bit is set to 1 before writing to the tdr. (2) multiple receive errors: table 9-10 lists the values of flag bits in the ssr when multiple receive errors occur, and indicates whether the rsr contents are transferred to the rdr. table 9-10. ssr bit states and data transfer when multiple receive errors occur * 1 set to 1 before the overrun error occurs. * 2 yes: the rsr contents are transferred to the rdr. no: the rsr contents are not transferred to the rdr. interrupt description priority eri receive-error interrupt, requested when orer, fer, or per high is set. rie must also be set. rxi receive-end interrupt, requested when rdrf and rie are set. txi transmit-end interrupt, requested when tdre and tie are set. low ssr bits receive error rdrf orer fer per rsr rdr* 2 overrun error 1* 1 1 0 0 no framing error 0 0 1 0 yes parity error 0 0 0 1 yes overrun + framing errors 1* 1 1 1 0 no overrun + parity errors 1* 1 1 0 1 no framing + parity errors 0 0 1 1 yes overrun + framing + parity errors 1* 1 1 1 1 no 193
(3) line break detection: when the rxd pin receives a continuous stream of 0s in asynchro- nous mode (line-break state), a framing error occurs because the sci detects a 0 stop bit. the value h?0 is transferred from the rsr to the rdr. software can detect the line-break state as a framing error accompanied by h?0 data in the rdr. the sci continues to receive data, so if the fer bit is cleared to 0 another framing error will occur. (4) sampling timing and receive margin in asynchronous mode: the serial clock used by the sci in asynchronous mode runs at 16 times the baud rate. the falling edge of the start bit is detected by sampling the rxd input on the falling edge of this clock. after the start bit is detected, each bit of receive data in the frame (including the start bit, parity bit, and stop bit or bits) is sampled on the rising edge of the serial clock pulse at the center of the bit. see figure 9-6. it follows that the receive margin can be calculated as in equation (1). when the absolute frequency deviation of the clock signal is 0 and the clock duty factor is 0.5, data can theoretically be received with distortion up to the margin given by equation (2). this is a theoretical limit, however. in practice, system designers should allow a margin of 20% to 30%. 194
figure 9-5. sampling timing (asynchronous mode) m = {(0.5 ?1/2n) ?(d ?0.5)/n ?(l ?0.5)f} ? 100 [%] (1) m : receive margin n : ratio of basic clock to baud rate (n = 16) d : duty factor of clock?atio of high pulse width to low width (0.5 to 1.0) l : frame length (9 to 12) f : absolute clock frequency deviation when d = 0.5 and f= 0 m = (0.5 ?1/2 16) 100 [%] = 46.875% (2) 1 2 4 0 5 6 7 8 9 3 2 1 2 3 4 5 6 7 8 9 1 1 1 1 2 1 3 1 4 1 5 1 6 1 0 1 3 1 4 1 5 1 6 1 2 1 0 1 1 3 4 5 basic clock sync sampling data sampling d0 d1 receive data start bit ?.5 pulses +7.5 pulses 195
section 10. ram 10.1 overview the h8/3257 and h8/3256 have 2 kbytes of on-chip static ram, h8/325 and h8/324 have 1 kbyte, the h8/323 has 512 bytes, and the h8/322 has 256 bytes. the on-chip ram is connected to the cpu by a 16-bit data bus. both byte and word access to the on-chip ram are performed in two states, enabling rapid data transfer and instruction execution. the on-chip ram occupies the following addresses in the chips address space. h8/3257, h8/3256: h'f780 to h'ff7f h8/325, h8/324: h'fb80 to h'ff7f h8/323: h'fd80 to h'ff7f h8/322: h'fe80 to h'ff7f the rame bit in the system control register (syscr) can enable or disable the on-chip ram, permitting these addresses to be allocated to external memory instead, if so desired. 10.2 block diagram figure 10-1 is a block diagram of the on-chip ram. figure 10-1. block diagram of on-chip ram (h8/3257) h'ff7e internal data bus (lower 8 bits) address h'f782 h'f780 internal data bus (upper 8 bits) h'ff7f h'ff7e h'f782 h'f780 h'f783 h'f781 even address odd address on-chip ram fig 10-1 197
10.3 ram enable bit (rame) the on-chip ram is enabled or disabled by the rame (ram enable) bit in the system control register (syscr). table 10-1 lists information about the system control register. table 10-1. system control register the only bit in the system control register that concerns the on-chip ram is the rame bit. see section 2.4.2, system control register for the other bits. bit 0 ?ram enable (rame): this bit enables or disables the on-chip ram. the rame bit is initialized to 1 on the rising edge of the res signal, so a reset enables the on-chip ram. the rame bit is not initialized in the software standby mode. 10.4 operation 10.4.1 expanded modes (modes 1 and 2) if the rame bit is set to 1, accesses to the following addresses are directed to the on-chip ram. h8/3257, h8/3256: h'f780 to h'ff7f h8/325, h8/324: h'fb80 to h'ff7f h8/323: h'fd80 to h'ff7f h8/322: h'fe80 to h'ff7f if the rame bit is cleared to 0, accesses to these addresses are directed to the external data bus. name abbreviation r/w initial value address system control register syscr r/w h?b h?fc4 bit 7 6 5 4 3 2 1 0 ssby sts2 sts1 sts0 nmieg rame initial value 0 0 0 0 1 0 1 1 read/write r/w r/w r/w r/w r/w r/w bit 7 rame description 0 on-chip ram is disabled. 1 on-chip ram is enabled. (initial value) 198
10.4.2 single-chip mode (mode 3) if the rame bit is set to 1, accesses to the following addresses are directed to the on-chip ram. h8/3257, h8/3256: h'f780 to h'ff7f h8/325, h8/324: h'fb80 to h'ff7f h8/323: h'fd80 to h'ff7f h8/322: h'fe80 to h'ff7f if the rame bit is cleared to 0, the on-chip ram data cannot be accessed. attempted write access has no effect. attempted read access always results in h?f data being read. 199
section 11. rom 11.1 overview the h8/3257 has 60 kbytes of high-speed, on-chip rom. the h8/3256 has 48 kbytes. the h8/325 has 32 kbytes. the h8/324 has 24 kbytes. the h8/323 has 16 kbytes. the h8/322 has 8 kbytes. the on-chip rom is connected to the cpu via a 16-bit data bus. both byte data and word data are accessed in two states, enabling rapid data transfer and instruction fetching. the h8/3257, h8/3256, h8/325, h8/323, and h8/322 are available in two versions: one with electrically programmable rom (prom); the other with masked rom. the prom version has a prom mode in which the chip can be programmed with a standard prom writer. the on-chip rom is enabled or disabled depending on the mcu operating mode, which is determined by the inputs at the mode pins (md 1 and md 0 ) when the chip comes out of the reset state. see table 11-1. table 11-1. on-chip rom usage in each mcu mode mode pins mode md 1 md 0 on-chip rom mode 1 (expanded mode) 0 1 disabled (external addresses) mode 2 (expanded mode) 1 0 enabled mode 3 (single-chip mode) 1 1 enabled 201
11.1.1 block diagram figure 11-1 is a block diagram of the on-chip rom. figure 11-1. block diagram of on-chip rom (h8/3257) 11.2 prom mode 11.2.1 prom mode setup in the prom mode of the prom version of the h8/3257 and h8/3256, the usual microcomputer functions are halted to allow the on-chip prom to be programmed. the programming method is the same as for the hn27c101. in the prom mode of the prom version of the h8/325, h8/323, and h8/322 the usual microcomputer functions are halted to allow the on-chip prom to be programmed. the programming method is the same as for the hn27c256. to select the prom mode, apply the signal inputs listed in table 11-2. table 11-2. selection of prom mode pin input mode pin md 1 low mode pin md 0 low stby pin low pins p7 0 and p7 1 high h'0002 h'0000 internal data bus (lower 8 bits) internal data bus (upper 8 bits) h'0003 h'0001 h'efff h'effe on-chip rom even addresses odd addresses fig 11-1 202
11.2.2 socket adapter pin assignments and memory map the h8/3257, h8/3256, h8/325, h8/323, and h8/322 can be programmed with a general-purpose prom writer. since the microcontroller package has 64 pins instead of 28 or 32 pins, a socket adapter is necessary. table 11-3 lists recommended socket adapters. figures 11-2 and 11-3 show the socket adapter pin assignments by giving the correspondence between microcontroller pins and hn27c101 or hn27c256 pin functions. figures 11-4 to 11-8 show memory maps in prom mode. since the h8/3257 has 60 kbytes of on- chip prom, the address range should be specified as h?000 to h?fff. h?f data should be specified for unused address areas. the h8/3256 has only 48 kbytes of prom. the h8/325 has only 32 kbytes. the h8/323 has only 16 kbytes. the h8/322 has only 8 kbytes. when programming these microcontrollers with a prom writer, specify an address range of h?000 to h?fff for the h8/3256, h?000 to h?fff for the h8/325, h?000 to h?fff for the h8/323, or h?000 to h?fff for the h8/322. specify h?f data for addresses equal to or greater than h?000 (h8/3256), h?000 (h8/325), h?000 (h8/323) or h?000 (h8/322). also specify h?f data for unused address areas. if these areas are programmed by mistake, it may become impossible to write or verify prom data. be particularly careful with microcontrollers in plastic packages, in which the prom cannot be reprogrammed. table 11-3. recommended socket adapters type package recommended socket adapter h8/3257 64-pin windowed shrink dip (dc-64s) hs3257ess01h h8/3256 64-pin shrink dip (dp-64s) 64-pin qfp (fp-64a) hs3257esh01h 68-pin plcc (cp-68) hs3257esc01h h8/325 64-pin windowed shrink dip (dc-64s) hs328ess01h h8/323 64-pin shrink dip (dp-64s) h8/322 64-pin qfp (fp-64a) hs328esh01h 68-pin plcc (cp-68) hs328esc01h 203
figure 11-2. socket adapter pin assignments l l l l l l l cp-68 fp-64a dc-64s, dp-64s pin 9 64 8 res 14 5 13 nmi 19 9 17 p4 0 20 10 18 p4 1 21 11 19 p4 2 22 12 20 p4 3 23 13 21 p4 4 24 14 22 p4 5 25 15 23 p4 6 26 16 24 p4 7 60 48 56 p1 0 59 47 55 p1 1 58 46 54 p1 2 57 45 53 p1 3 56 44 52 p1 4 55 43 51 p1 5 54 42 50 p1 6 53 41 49 p1 7 50 39 47 p2 0 49 38 46 p2 1 48 37 45 p2 2 47 36 44 p2 3 46 35 43 p2 4 45 34 42 p2 5 44 33 41 p2 6 43 32 40 p2 7 27 17 25 p5 0 28 18 26 p5 1 29 19 27 p5 2 33 23 31 p7 0 34 24 32 p7 1 15 6 14 v cc 42 31 39 v cc 13 4 12 md 0 12 3 11 md 1 16 7 15 stby 17 8 16 v ss 52 40 48 v ss eprom socket pin hn27c101 (32 pins) v pp 1 ea 9 26 eo 0 13 eo 1 14 eo 2 15 eo 3 17 eo 4 18 eo 5 19 eo 6 20 eo 7 21 ea 0 12 ea 1 11 ea 2 10 ea 3 9 ea 4 8 ea 5 7 ea 6 6 ea 7 5 ea 8 27 oe 24 ea 10 23 ea 11 25 ea 12 4 ea 13 28 ea 14 29 ce 22 ea 15 3 ea 16 2 pgm 31 v cc 32 v ss 16 note: all pins not listed in this figure should be left open. notation v pp : programming voltage (12.5 v) eo 7 to eo 0 : data input/output ea 16 to ea 0 : address input oe: output enable ce: chip enable pgm: program enable h8/3257, h8/3256 204
figure 11-3. socket adapter pin assignments l l l l l l l h8/325, h8/323, h8/322 fp-64a dc-64s, dp-64s cp-68 pin 64 8 9 res 5 13 14 nmi 9 17 19 p4 0 10 18 20 p4 1 11 19 21 p4 2 12 20 22 p4 3 13 21 23 p4 4 14 22 24 p4 5 15 23 25 p4 6 16 24 26 p4 7 48 56 60 p1 0 47 55 59 p1 1 46 54 58 p1 2 45 53 57 p1 3 44 52 56 p1 4 43 51 55 p1 5 42 50 54 p1 6 41 49 53 p1 7 39 47 50 p2 0 38 46 49 p2 1 37 45 48 p2 2 36 44 47 p2 3 35 43 46 p2 4 34 42 45 p2 5 33 41 44 p2 6 32 40 43 p2 7 23 31 33 p7 0 24 32 34 p7 1 6 14 15 v cc 31 39 42 v cc 4 12 13 md 0 3 11 12 md 1 7 15 16 stby 8 16 17 v ss 40 48 52 v ss pin hn27c256h v pp 1 ea 9 24 eo 0 11 eo 1 12 eo 2 13 eo 3 15 eo 4 16 eo 5 17 eo 6 18 eo 7 19 ea 0 10 ea 1 9 ea 2 8 ea 3 7 ea 4 6 ea 5 5 ea 6 4 ea 7 3 ea 8 25 oe 22 ea 10 21 ea 11 23 ea 12 2 ea 13 26 ea 14 27 ce 20 v cc 28 v ss 14 hn27c256 (pin 28) note: all pins not listed in this figure should be left open. notation v pp : programming voltage (12.5 v) eo 7 to eo 0 : data input/output ea 14 to ea 0 : address input oe: output enable ce: chip enable 205
figure 11-4. h8/3257 memory map in prom mode figure 11-5. h8/3256 memory map in prom mode h'efff h'efff address in prom mode address in mcu mode h'0000 h'0000 on-chip prom undetermined output* h'1ffff note: if this address area is read in prom mode, the output data are undetermined. h'bfff h'bfff address in prom mode address in mcu mode h'0000 h'0000 on-chip prom undetermined output* h'1ffff note: if this address area is read in prom mode, the output data are undetermined. 206
figure 11-6. memory map of the h8/325 in prom mode figure 11-7. memory map of the h8/323 in prom mode figure 11-8. memory map of the h8/322 in prom mode h'7fff h'7fff address in prom mode address in mcu mode h'0000 h'0000 on-chip prom fig 11-3 h'7fff address in prom mode address in mcu mode h'0000 h'0000 fig 11-4 "1" output* h'7fff note: in prom mode, addresses in this area always read h'ff. on-chip prom h'7fff address in prom mode address in mcu mode h'0000 h'0000 on-chip prom fig 11-5 "1" output* h'7fff h'1fff h'1fff note: in prom mode, addresses in this area always read h'ff. 207
11.3 programming 11.3.1 selection of sub-modes in prom mode (1) case of h8/3257 and h8/3256 the write, verify, and other sub-modes of the prom mode are selected as shown in table 11-4. table 11-4. selection of sub-modes in prom mode pins sub-mode ce oe pgm v pp v cc e0 7 to e0 0 ea 16 to ea 0 write low high low v pp v cc data input address input verify low low high v pp v cc data output address input programming low low low v pp v cc high-impedance address input inhibited low high high high low low high high high note: the v pp and v cc pins must be held at the v pp and v cc voltage levels. the h8/3257 or h8/3256 prom has the same standard read/write specifications as the hn27c101 eprom. page programming is not supported, however, so do not select page programming mode. prom writers that provide only page programming cannot be used. when selecting a prom writer, check that it supports the byte-at-a-time high-speed programming mode. be sure to set the address range to h?000 to h?fff for the h8/3257, and to h?000 to h?fff for the h8/3256. 208
(2) case of h8/325, h8/323, and h8/322 the write, verify, inhibited, and read sub-modes of the prom mode are selected as shown in table 11-5. table 11-5. selection of sub-modes in prom mode pins mode ce oe v pp v cc e0 7 to e0 0 ea 14 to ea 0 write low high v pp v cc data input address input verify high low v pp v cc data output address input programming inhibited high high v pp v cc high-impedance address input note: the v pp and v cc pins must be held at the v pp and v cc voltage levels. the h8/325 prom uses the same, standard read/write specifications as the hn27c256 and hn27256. 11.3.2 writing and verifying an efficient, high-speed programming procedure can be used to write and verify prom data. this procedure writes data quickly without subjecting the chip to voltage stress and without sacrificing data reliability. it leaves the data h?f written in unused addresses. 209
figures 11-9 to 11-10 show the basic high-speed programming flowchart. tables 11-6 and 11-8 list the electrical characteristics of the chip in the prom mode. figure 11-11 shows a write/verify timing chart. figure 11-9. high-speed programming flowchart (h8/3257, h8/3256) start address = 0 n = 0 set read mode vcc = 5.0v, vpp = vcc 0.6 end y n y n y n < 25? all addresses read? error n y n + 1 n address + 1 address n last address? program t = 0.2 ms 5% pw program t = 0.2n ms opw verify ok? set program/verify mode vcc = 6.0v 0.25v, vpp = 12.5v 0.3v fig. 11-9 210
figure 11-10. high-speed programming flowchart (h8/325, h8/323, h8/322) start address = 0 n = 0 set read mode vcc = 5.0v 0.5v, vpp = vcc 0.6 end y n y n y n < 25? all addresses read? error n y n + 1 n address + 1 address n last address? write time t = 1 ms 5% pw write t = 3n ms opw verify ok? set program/verify mode vcc = 6.0v 0.25v, vpp = 12.5v 0.3v figure 11-10 211
table 11-6. dc characteristics (when v cc = 6.0v 0.25v, v pp = 12.5v 0.3v, v ss = 0v, ta = 25?c 5?c) measurement item symbol min typ max unit conditions input high voltage eo 7 ?eo 0 , v ih 2.4 v cc + 0.3 v ea 14 ?ea 0 , oe, ce input low voltage eo 7 ?eo 0 , v il ?0.3 0.8 v ea14 ?ea 0 , oe, ce output high voltage eo 7 ?eo 0 v oh 2.4 v i oh = ?00 a output low voltage eo 7 ?eo 0 v ol 0.45 v i ol = 1.6 ma input leakage eo 7 ?eo 0 , |i li | 2 a v in = 5.25v/ current ea 14 ?ea 0 , 0.5v oe, ce v cc current i cc 40 ma v pp current i pp 40 ma table 11-7. ac characteristics (h8/3257, h8/3256) (when v cc = 6.0v 0.25v, v pp = 12.5v 0.3v, ta = 25?c 5?c) measurement item symbol min typ max unit conditions address setup time t as 2 s see figure 11-11* oe setup time t oes 2 s data setup time t ds 2 s address hold time t ah 0 s data hold time t dh 2 s data output disable time t df 130 ns vpp setup time t vps 2 s program pulse width t pw 0.19 0.20 0.21 ms oe pulse width for t opw 0.19 5.25 ms overwrite-programming v cc setup time t vcs 2 s ce setup time t ces 2 s data output delay time t oe 0 150 ns * input pulse level: 0.8v to 2.2v input rise/fall time 20 ns timing reference levels: input?.0v, 2.0v; output?.8v, 2.0v < = 212
table 11-8. ac characteristics (h8/325, h8/323, h8/322) (when v cc = 6.0v 0.25v, v pp = 12.5v 0.3v, ta = 25?c 5?c) measurement item symbol min typ max unit conditions address setup time t as 2 s see figure 11-11* oe setup time t oes 2 s data setup time t ds 2 s address hold time t ah 0 s data hold time t dh 2 s data output disable time t df 130 ns vpp setup time t vps 2 s program pulse width t pw 0.95 1.0 1.05 ms oe pulse width for t opw 2.85 78.75 ms overwrite-programming vcc setup time t vcs 2 s data output delay time t oe 0 500 ns * input pulse level: 0.8v to 2.2v input rise/fall time 20 ns timing reference levels: input?.0v, 2.0v; output?.8v, 2.0v < = 213
figure 11-11. prom write/verify timing oe ce write verify address data input data output data t vps t ds t dh t as t ah t df v pp v pp v cc v cc gnd t vcs t pw t opw t oes t oe v cc 214
11.3.3 notes on writing (1) write with the specified voltages and timing. the programming voltage (v pp ) is 12.5 v. caution: applied voltages in excess of the specified values can permanently destroy the chip. be particularly careful about the prom writers overshoot characteristics. if the prom writer is set to intel specifications or hitachi hn27c101, hn27256 or hn27c256 specifications, v pp will be 12.5 v. (2) before writing data, check that the socket adapter and chip are correctly mounted in the prom writer. overcurrent damage to the chip can result if the index marks on the prom writer, socket adapter, and chip are not correctly aligned. (3) don? touch the socket adapter or chip while writing. touching either of these can cause contact faults and write errors. (4) page programming is not supported. do not select page programming mode. 11.3.4 reliability of written data an effective way to assure the data holding characteristics of the programmed chips is to bake them at 150?c, then screen them for data errors. this procedure quickly eliminates chips with prom memory cells prone to early failure. figure 11-12 shows the recommended screening procedure. figure 11-12. recommended screening procedure write program read and check program vcc = 4.5 v and 5.5 v install baking time should be measured from the point when the baking oven reaches 150 c. note: bake with power off 150 10 c, 48 hr + 8 hr * ?0 hr fig. 11-6 215
if a series of write errors occurs while the same prom writer is in use, stop programming and check the prom writer and socket adapter for defects, using a microcomputer chip with a windowed package and on-chip eprom. please inform hitachi of any abnormal conditions noted during programming or in screening of program data after high-temperature baking. 11.3.5 erasing of data the windowed package enables data to be erased by illuminating the window with ultraviolet light. table 11-9 lists the erasing conditions. table 11-9. erasing conditions item value ultraviolet wavelength 253.7 nm minimum illumination 15w?/cm 2 the conditions in table 11-9 can be satisfied by placing a 12000-w/cm 2 ultraviolet lamp 2 or 3 centimeters directly above the chip and leaving it on for about 20 minutes. 11.4 handling of windowed packages (1) glass erasing window: rubbing the glass erasing window of a windowed package with a plastic material or touching it with an electrically charged object can create a static charge on the window surface which may cause the chip to malfunction. if the erasing window becomes charged, the charge can be neutralized by a short exposure to ultraviolet light. this returns the chip to its normal condition, but it also reduces the charge stored in the floating gates of the prom, so it is recommended that the chip be reprogrammed afterward. accumulation of static charge on the window surface can be prevented by the following precautions: ? when handling the package, ground yourself. dont wear gloves. avoid other possible sources of static charge. - avoid friction between the glass window and plastic or other materials that tend to accumulate static charge. 216
a be careful when using cooling sprays, since they may have a slight ion content. cover the window with an ultraviolet-shield label, preferably a label including a conductive material. besides protecting the prom contents from ultraviolet light, the label protects the chip by distributing static charge uniformly. (2) handling after programming: fluorescent light and sunlight contain small amounts of ultraviolet, so prolonged exposure to these types of light can cause programmed data to invert. in addition, exposure to any type of intense light can induce photoelectric effects that may lead to chip malfunction. it is recommended that after programming the chip, you cover the erasing window with a light-proof label (such as an ultraviolet-shield label). 217
section 12. power-down state 12.1 overview the h8/325 series has a power-down state that greatly reduces power consumption by stopping some or all of the chip functions. the power-down state includes three modes: (1) sleep mode ?a software-triggered mode in which the cpu halts but the rest of the chip remains active (2) software standby mode ?a software-triggered mode in which the entire chip is inactive (3) hardware standby mode ?a hardware-triggered mode in which the entire chip is inactive table 12-1 lists the conditions for entering and leaving the power-down modes. it also indicates the status of the cpu, on-chip supporting modules, etc. in each power-down mode. table 12-1. power-down state * on-chip supporting modules. notes 1. syscr: system control register 2. ssby: software standby bit entering cpu sup. i/o exiting mode procedure clock cpu regs. mod.* ram ports methods sleep execute run halt held run held held interrupt mode sleep res instruction stby soft- set ssby bit halt halt held halt held held nmi ware in syscr to and irq 0 ?irq 2 standby 1, then initial- stby mode execute sleep ized res instruction is hard- set stby halt halt not halt held high stby high, ware pin to low held and impe- then res standby level initialized dance low ? high mode state 219
12.2 system control register: power-down control bits bits 7 to 4 of the system control register (syscr) concern the power-down state. specifically, they concern the software standby mode. table 12-2 lists the attributes of the system control register. table 12-2. system control register bit 7 ?software standby (ssby): this bit enables or disables the transition to the software standby mode. on recovery from the software standby mode by an external interrupt or input strobe interrupt, ssby remains set to 1. to clear this bit, software must write a 0. bits 6 to 4 ?standby timer select 2 to 0 (sts2 to sts0): these bits select the clock settling time when the chip recovers from the software standby mode by an external interrupt. during the selected time, the clock oscillator runs but clock pulses are not supplied to the cpu or the on-chip supporting modules. name abbreviation r/w initial value address system control register syscr r/w h?b h?fc4 bit 7 6 5 4 3 2 1 0 ssby sts2 sts1 sts0 nmieg rame initial value 0 0 0 0 1 0 1 1 read/write r/w r/w r/w r/w r/w r/w bit 7 ssby description 0 the sleep instruction causes a transition to the sleep mode. (initial value) 1 the sleep instruction causes a transition to the software standby mode. 220
when the on-chip clock generator is used, the sts bits should be set to allow a settling time of at least 10 ms. table 12-3 lists the settling times selected by these bits at several clock frequencies and indicates the recommended settings. when the chip is externally clocked, the sts bits can be set to any value. the minimum value (sts2 = sts1 = sts0 = 0) is recommended. table 12-3. times set by standby timer select bits (unit: ms) notes: 1. all times are in milliseconds. 2. recommended values are printed in boldface. 12.3 sleep mode the sleep mode provides an effective way to conserve power while the cpu is waiting for an external interrupt or an interrupt from an on-chip supporting module. bit 6 bit 5 bit 4 sts2 sts1 sts0 description 0 0 0 settling time = 8192 states (initial value) 0 0 1 settling time = 16384 states 0 1 0 settling time = 32768 states 0 1 1 settling time = 65536 states 1 settling time = 131072 states settling time system clock frequency (mhz) sts2 sts1 sts0 (states) 10 8 6 4 2 1 0.5 0 0 0 8192 0.8 1.0 1.4 2.0 4.1 8.2 16.4 0 0 1 16384 1.6 2.0 2.7 4.1 8.2 16.4 32.8 0 1 0 32768 3.3 4.1 5.5 8.2 16.4 32.8 65.5 0 1 1 65536 6.6 8.2 10.9 16.4 32.8 65.5 131.1 1 131072 13.1 16.4 21.8 32.8 65.5 131.1 262.1 221
12.3.1 transition to sleep mode when the ssby bit in the system control register is cleared to 0, execution of the sleep instruction causes a transition from the program execution state to the sleep mode. after executing the sleep instruction, the cpu halts, but the contents of its internal registers remain unchanged. the on-chip supporting modules continue to operate normally. 12.3.2 exit from sleep mode the chip wakes up from the sleep mode when it receives an internal or external interrupt request, or a low input at the res or stby pin. (1) wake-up by interrupt: an interrupt releases the sleep mode and starts the cpus interrupt- handling sequence. if an interrupt from an on-chip supporting module is disabled by the corresponding enable/disable bit in the modules control register, the interrupt cannot be requested, so it cannot wake the chip up. similarly, the cpu cannot be awoken by an interrupt other than nmi if the i (interrupt mask) bit in the ccr (condition code register) is set when the sleep instruction is executed. (2) wake-up by res pin: when the res pin goes low, the chip exits from the sleep mode to the reset state. (3) wake-up by stby pin: when the stby pin goes low, the chip exits from the sleep mode to the hardware standby mode. 12.4 software standby mode in the software standby mode, the system clock stops and chip functions halt, including both cpu functions and the functions of the on-chip supporting modules. power consumption is reduced to an extremely low level. the on-chip supporting modules and their registers are reset to their initial states, but as long as a minimum necessary voltage supply is maintained (at least 2v), the contents of the cpu registers and on-chip ram remain unchanged. i/o ports also remain unchanged. 222
12.4.1 transition to software standby mode to enter the software standby mode, set the standby bit (ssby) in the system control register (syscr) to 1, then execute the sleep instruction. 12.4.2 exit from software standby mode the chip can be brought out of the software standby mode by an input at one of seven pins: nmi, irq 0 , irq 1 , irq 2 , is, res, or stby. (1) recovery by external interrupt: when an nmi, irq 0 , irq 1 , irq 2 , or input strobe (isi) interrupt request signal is received, the clock oscillator begins operating. after the waiting time set in the system control register (bits sts2 to sts0), clock pulses are supplied to the cpu and on- chip supporting modules. the cpu executes the interrupt-handling sequence for the requested interrupt, then returns to the instruction after the sleep instruction. the ssby bit is not cleared. see section 12.2, system control register: power-down control bits for information about the sts bits. (2) recovery by res pin: when the res pin goes low, the clock oscillator starts. next, when the res pin goes high, the cpu begins executing the reset sequence. the ssby bit is cleared to 0. the res pin must be held low long enough for the clock to stabilize. (3) recovery by stby pin: when the stby pin goes low, the chip exits from the software standby mode to the hardware standby mode. 12.4.3 sample application of software standby mode in this example the chip enters the software standby mode when nmi goes low and exits when nmi goes high, as shown in figure 12-1. 223
the nmi edge bit (nmieg) in the system control register is originally cleared to 0, selecting the falling edge. when nmi goes low, the nmi interrupt handling routine sets nmieg to 1 (selecting the rising edge), sets ssby to 1, then executes the sleep instruction. the chip enters the software standby mode. it recovers from the software standby mode on the next rising edge of nmi. figure 12-1. software standby mode nmi timing (example) 12.4.4 notes on current dissipation 1. the i/o ports remain in their current states in software standby mode. if a port is in the high output state, it continues to dissipate power in proportion to the output current. 2. when software standby mode is entered under condition (a) or (b) below, current dissipation is higher (i cc = 100 to 300 a) than normal in standby mode. (a) in single-chip mode (mode 3): when software standby mode is entered by executing an instruction stored in on-chip rom, after even one instruction not stored in on-chip rom has been fetched (e.g. from on-chip ram). clock generator nmi ssby nmieg settling time nmi interrupt handler nmieg = 1 ssby = 1 software standby mode (power-down state) nmi interrupt handler sleep fig 12-1 224
(b) in expanded mode with on-chip rom enabled (mode 2): when software standby mode is entered by executing an instruction stored in on-chip rom, after even one instruction not stored in on-chip rom has been fetched (e.g. from external memory or on-chip ram). note that the h8/300 cpu pre-fetches instructions. if an instruction stored in the last two bytes of on-chip rom is executed, the contents of the next two bytes, not in on-chip rom, will be fetched as the next instruction. this problem does not occur in expanded mode when on-chip rom is disabled (mode 1). in hardware standby mode there is no additional current dissipation, regardless of the conditions when hardware standby mode is entered. 12.5 hardware standby mode 12.5.1 transition to hardware standby mode regardless of its current state, the chip enters the hardware standby mode whenever the stby pin goes low. the hardware standby mode reduces power consumption drastically by halting the cpu, stopping all the functions of the on-chip supporting modules, and placing i/o ports in the high-impedance state. the registers of the on-chip supporting modules are reset to their initial values. only the on- chip ram is held unchanged, provided the minimum necessary voltage supply is maintained (at least 2v). notes: 1. the rame bit in the system control register should be cleared to 0 before the stby pin goes low, to disable the on-chip ram during the hardware standby mode. 2. do not change the inputs at the mode pins (md 1 , md 0 ) during hardware standby mode. be particularly careful not to let both mode pins go low in hardware standby mode, since that places the chip in prom mode and increases current drain. 225
12.5.2 recovery from hardware standby mode recovery from the hardware standby mode requires inputs at both the stby and res pins. when the stby pin goes high the clock oscillator begins running. the res pin should be low at this time and should be held low long enough for the clock to stabilize. when the res pin changes from low to high, the reset sequence is executed and the chip returns to the program execution state. 12.5.3 timing relationships figure 12-2 shows the timing relationships in the hardware standby mode. in the sequence shown, first res goes low, then stby goes low, at which point the chip enters the hardware standby mode. to recover, first stby goes high, then after the clock settling time, res goes high. figure 12-2. hardware standby mode timing clock pulse generator res stby clock settling time restart fig 12-2 226
section 13. e-clock interface 13.1 overview for interfacing to peripheral devices that require it, the h8/325 series can generate an e clock output. special instructions (movtpe, movfpe) perform data transfers synchronized with the e clock. the e clock is created by dividing the system clock () by 8. the e clock is output at the p4 7 pin when the p4 7 ddr bit in the port 4 data direction register (p4ddr) is set to 1. it is output only in the expanded modes (mode 1 and mode 2); it is not output in the single-chip mode. output begins immediately after a reset. when the cpu executes an instruction that synchronizes with the e clock, the address strobe (as), the address on the address bus, and the ios signal are output as usual, but the rd and wr signal lines and the data bus do not become active until the falling edge of the e clock is detected. the length of the access cycle for an instruction synchronized with the e clock accordingly varies from 9 to 16 states. figures 15-1 and 15-2 show the timing in the cases of maximum and minimum synchronization delay. it is not possible to insert wait states (t w ) during the execution of an instruction synchronized with the e clock by input at the wait pin. 227
t 1 t 2 t e t e t e t e t e t e t e t e t e t e t e t e t e t 3 e as d 7 to d 0 d 7 to d 0 a 15 to a 0 , ios rd (read access) wr (write access) (read access) (write access) fig 13-1 figure 13-1. execution cycle of instruction synchronized with e clock in expanded modes (maximum synchronization delay) 228
figure 13-2. execution cycle of instruction synchronized with e clock in expanded modes (minimum synchronization delay) last state t 1 t 2 t e t e t e t e t e t e t 3 e a 15 to a 0 , ios as rd (read access) wr (write access) d 7 to d 0 (read access) d 7 to d 0 (write access) fig 13-2 229
section 14. clock pulse generator 14.1 overview the h8/325 series chips have a built-in clock pulse generator (cpg) consisting of an oscillator circuit, a system clock divider, an e clock divider, and a prescaler. the prescaler generates clock signals for the on-chip supporting modules. 14.1.1 block diagram figure 14-1. block diagram of clock pulse generator 14.2 oscillator circuit if an external crystal is connected across the extal and xtal pins, the on-chip oscillator circuit generates a clock signal for the system clock divider. alternatively, an external clock signal can be applied to the extal pin. (1) connecting an external crystal circuit configuration: an external crystal can be connected as in the example in figure 14-2. an at-cut parallel resonating crystal should be used. xtal extal e /2 to /4096 prescaler oscillator circuit 2 divider 8 divider cpg 231
figure 14-2. connection of crystal oscillator (example) crystal oscillator: the external crystal should have the characteristics listed in table 16-1. table 14-1. external crystal parameters frequency (mhz) 2 4 8 12 16 20 rs max ( ) 500 120 60 40 30 20 c 0 (pf) 7 pf max figure 14-3. equivalent circuit of external crystal a note on board design: when an external crystal is connected, other signal lines should be kept away from the crystal circuit to prevent induction from interfering with correct oscillation. see figure 14-4. the crystal and its load capacitors should be placed as close as possible to the xtal and extal pins. extal xtal c l1 c l1 = c l2 = 15 to 22 pf c l2 fig 14-2 c l c 0 xtal extal l r s at-cut parallel resonating crystal 232
figure 14-4. notes on board design around external crystal (2) input of external clock signal circuit configuration: figure 14-5 shows examples of signal connections for external clock input. in example (b), the external clock signal should be held high during the standby modes. figure 14-5. external clock input (example) external clock input frequency double the system clock () frequency duty factor 45% to 55% extal xtal external clock input 74hc04 fig 14-5 extal xtal external clock input open (a) (b) not allowed signal a signal b h8/325 series xtal extal c l1 c l2 fig 14-4 233
14.3 system clock divider the system clock divider divides the crystal oscillator or external clock frequency by 2 to create the system clock (). an e clock signal is created by dividing the system clock by 8. figure 16-6 shows the phase relationship of the e clock to the system clock. figure 14-6. phase relationship of system clock and e clock e 234
section 15. electrical specifications 15.1 absolute maximum ratings table 15-1 lists the absolute maximum ratings. table 15-1. absolute maximum ratings note: the input pins have protection circuits that guard against high static voltages and electric fields, but these high input-impedance circuits should never receive overvoltages exceeding the absolute maximum ratings shown in table 15-1. 15.2 electrical characteristics 15.2.1 dc characteristics tables 15-2 and 15-3 list the dc characteristics of the h8/325 series. item symbol rating unit supply voltage v cc ?.3 to +7.0 v programming voltage v pp ?.3 to +13.5 v input voltage v in ?.3 to v cc + 0.3 v operating temperature t opr regular specifications: ?0 to +75 ?c wide-range specifications: ?0 to +85 ?c storage temperature t stg ?5 to +125 ?c 235
table 15-2. dc characteristics (5v version) conditions: v cc = 5.0v 10%, v ss = 0v, ta = ?0 to 75?c (regular specifications) ta = ?0 to 85?c (wide-range specifications) measurement item symbol min typ max unit conditions schmitt trigger p6 6 to p6 3 , p6 0 , v t - 1.0 v input voltage p7 0 v t + v cc 0.7 v (1) v t + ? t - 0.4 v input high voltage res, stby v ih v cc ?0.7 v cc + 0.3 v (2) md 1 , md 0 extal, nmi input high voltage input pins v ih 2.0 v cc + 0.3 v other than (1) and (2) input low voltage res, stby v il ?.3 0.5 v (3) md 1 , md 0 , extal input low voltage input pins v il ?.3 0.8 v other than (1) and (3) output high all output pins v oh v cc ?0.5 v i oh = ?00 a voltage 3.5 v i oh = ?.0 ma output low all output pins v ol 0.4 v i ol = 1.6 ma voltage p1 7 to p1 0 , 1.0 v i ol = 10.0 ma p2 7 to p2 0 input leakage res |i in | 10.0 a v in = 0.5 v to current stby, nmi, 1.0 a v cc ?0.5 v md 1 , md 0 leakage current ports 1 to 7 |i tsi | 1.0 a v in = 0.5 v to in 3-state (off state) v cc ?0.5 v input pull-up ports 1 to 7 -ip 30 250 a v in = 0 v mos current 236
table 15-2. dc characteristics (5v version) (cont.) conditions: v cc = av cc = 5.0v 10%, v ss = 0v, ta = ?0 to 75?c (regular specifications) ta = ?0 to 85?c (wide-range specifications) notes: 1. current dissipation values assume that v ih min. = v cc ?0.5v, v il max. = 0.5v, all output pins are in the no-load state, and all mos input pull-ups are off. 2. for these values it is assumed that v ram v cc < 4.5 v and v ih min = v cc 0.9, v il max = 0.3 v. measurement item symbol min typ max unit conditions input capacitance res c in 60 pf v in = 0 v nmi 30 pf f = 1 mhz all input pins 15 pf ta = 25?c except res and nmi current normal i cc 12 25 ma f = 6 mhz dissipation *1 operation 16 30 ma f = 8 mhz 20 40 ma f = 10 mhz sleep mode 8 15 ma f = 6 mhz 10 20 ma f = 8 mhz 12 25 ma f = 10 mhz standby modes *2 0.01 5.0 a ram standby v ram 2.0 v voltage 237
table 15-3. dc characteristics (3v version for only h8/3257 and h8/3256) conditions: v cc = 2.7 to 3.6v, v ss = 0v, ta = ?0 to 75?c measurement item symbol min typ max unit conditions schmitt trigger p6 6 to p6 3 , p6 0 , v t - v cc 0.15 v input voltage p7 0 v t + v cc 0.7 v (1) v t + ? t - 0.2 v input high voltage res, stby v ih v cc 0.9 v cc + 0.3 v (2) md 1 , md 0 extal, nmi input high voltage input pins v ih v cc 0.7 v cc + 0.3 v other than (1) and (2) input low voltage res, stby v il ?.3 v cc 0.1 v (3) md 1 , md 0 , extal input low voltage input pins v il ?.3 v cc 0.15 v other than (1) and (3) output high all output pins v oh v cc ?0.4 v i oh = ?00 a voltage v cc ?0.9 v i oh = ?.0 ma output low p1 7 to p1 0 , v ol 0.4 v i ol = 1.6 ma voltage p2 7 to p2 0 all output pins 0.4 v i ol = 0.8 ma input leakage res |i in | 10.0 a v in = 0.5 v to current stby, nmi, 1.0 a v cc ?0.5 v md 1 , md 0 leakage current ports 1 to 7 |i tsi | 1.0 a v in = 0.5 v to in 3-state (off state) v cc ?0.5 v input pull-up ports 1 to 7 -ip 3 120 a v cc = 3.3 v mos current v in = 0 v 238
table 15-3. dc characteristics (3v version for only h8/3257 and h8/3256) (cont.) conditions: v cc = 2.7 to 3.6v, v ss = 0v, ta = ?0 to 75?c measurement item symbol min typ max unit conditions input capacitance res c in 60 pf v in = 0 v nmi 30 pf f = 1 mhz all input pins 15 pf ta = 25?c except res and nmi current normal i cc 4 ma f = 3 mhz dissipation* operation sleep mode 3 ma normal 6 12 ma f = 5 mhz operation sleep mode 4 8 ma standby modes 0.01 5.0 a ram standby v ram 2.0 v voltage note: current dissipation values assume that v ih min. = v cc ?0.5v, v il max. = 0.5v, all output pins are in the no-load state, and all mos input pull-ups are off. 239
table 15-4. allowable output current sink values conditions: v cc = 5.0v 10%, v ss = 0v, ta = ?0 to 75?c (regular specifications) ta = ?0 to 85?c (wide-range specifications) note: to avoid degrading the reliability of the chip, be careful not to exceed the output current sink values in table 15-4. in particular, when driving a darlington pair or led directly, be sure to insert a current-limiting resistor in the output path. see figures 17-1 and 17-2. figure 15-1. example of circuit for driving a darlington pair figure 15-2. example of circuit for driving a led h8/325 series port 2 k darlington pair fig. 15-1 vcc 600 led port 1 or 2 h8/325 series fig. 15-2 item symbol min typ max unit allowable output low ports 1 and 2 i ol 10 ma current sink (per pin) other output pins 2.0 ma allowable output low ports 1 and 2, total s i ol 80 ma current sink (total) all output pins 120 ma allowable output high all output pins ? oh 2.0 ma current sink (per pin) allowable output high total of all output s ? oh 40 ma current sink (total) 240
table 15-5. allowable output current sink values (3v version for only h8/3257 and h8/3256) conditions: v cc = 2.7 to 3.6v, v ss = 0v, ta = ?0 to 75?c item symbol min typ max unit allowable output low ports 1 and 2 i ol 2 ma current sink (per pin) other output pins 1.0 ma allowable output low ports 1 and 2, total of 16 pins s i ol 40 ma current sink (total) total of all other output pins 60 ma allowable output high all output pins ? oh 2.0 ma current sink (per pin) allowable output high total of all output pins s ? oh 30 ma current sink (total) note: to avoid degrading the reliability of the chip, be careful not to exceed the output current sink values in table 15-5. 241
15.2.2 ac characteristics the ac characteristics of the h8/325 series are listed in three tables. bus timing parameters are given in table 15-6, control signal timing parameters in table 15-7, and timing parameters of the on- chip supporting modules in table 15-8. table 15-6. bus timing condition a: v cc = 5.0v 10%, = 0.5 to 10mhz, v ss = 0v, ta = ?0 to 75?c (regular specifications), ta = ?0 to 85?c (wide-range specifications) condition b: v cc = 2.7 to 3.6v, v ss = 0v, ta = ?0 to 75?c, for only h8/3257 and h8/3256 condition b condition a 5mhz 6mhz 8mhz 10mhz measurement item symbol min max min max min max min max unit conditions clock cycle time t cyc 200 2000 166.7 2000 125 2000 100 2000 ns fig. 15-4 clock pulse width low t cl 65 65 45 35 ns fig. 15-4 clock pulse width high t ch 65 65 45 35 1ns fig. 15-4 clock rise time t cr 25 15 15 15 ns fig. 15-4 clock fall time t cf 25 15 15 15 ns fig. 15-4 address delay time t ad 90 70 60 55 ns fig. 15-4 address hold time t ah 30 30 25 20 ns fig. 15-4 address strobe delay time t asd 80 70 60 40 ns fig. 15-4 write strobe delay time t wsd 80 70 60 50 ns fig. 15-4 strobe delay time t sd 90 70 60 50 ns fig. 15-4 write strobe pulse width t wsw 200 200 150 120 ns fig. 15-4 address setup time 1 t as1 25 25 20 15 ns fig. 15-4 address setup time 2 t as2 105 105 80 65 ns fig. 15-4 read data setup time t rds 90 60 50 35 ns fig. 15-4 read data hold time t rdh 0 0 0 0 ns fig. 15-4 write data delay time t wdd 125 85 75 75 ns fig. 15-4 read data access time t acc 300 280 210 170 ns fig. 15-4 write data setup time t wds 10 30 15 10 ns fig. 15-4 write data hold time t wdh 30 30 25 20 ns fig. 15-4 wait setup time t wts 60 45 45 45 ns fig. 15-5 wait hold time t wth 20 10 10 10 ns fig. 15-5 e clock delay time t ed 30 25 25 25 ns fig. 15-6 e clock rise time t er 25 15 15 15 ns fig. 15-6 e clock fall time t ef 25 15 15 15 ns fig. 15-6 read data hold time t rdhe 0 0 0 0 ns fig. 15-6 (for e clock) write data hold time t wdhe 60 50 40 30 ns fig. 15-6 (for e clock) 242
table 15-7. control signal timing condition a: v cc = 5.0v 10%, = 0.5 to 10mhz, v ss = 0v, ta = ?0 to 75?c (regular specifications), ta = ?0 to 85?c (wide-range specifications) condition b: v cc = 2.7 to 3.6v, v ss = 0v, ta = ?0 to 75?c, for only h8/3257 and h8/3256 condition b condition a 5mhz 6mhz 8mhz 10mhz measurement item symbol min max min max min max min max unit conditions res setup time t ress 300 200 200 200 ns fig. 15-7 res pulse width t resw 10 10 10 10 t cyc fig. 15-7 mode programming t mds 4 4 4 4 t cyc fig. 15-7 setup time nmi setup time t nmis 300 150 150 150 ns fig. 15-8 (nmi, irq 0 to irq 2 ) nmi hold time t nmih 10 10 10 10 ns fig. 15-8 (nmi, irq 0 to irq 2 ) interrupt pulse width t nmiw 300 200 200 200 ns fig. 15-8 for recovery from soft- ware standby mode (nmi, irq 0 to irq 2 ) crystal oscillator settling t osc1 20 20 20 20 ms fig. 15-9 time (reset) crystal oscillator settling t osc2 10 10 10 10 ms fig. 15-10 time (software standby) table 15-8. timing conditions of on-chip supporting modules condition a: v cc = 5.0v 10%, = 0.5 to 10mhz, v ss = 0v, ta = ?0 to 75?c (regular specifications), ta = ?0 to 85?c (wide-range specifications) condition b: v cc = 2.7 to 3.6v, v ss = 0v, ta = ?0 to 75?c, for only h8/3257 and h8/3256 condition b condition a 5mhz 6mhz 8mhz 10mhz measurement item symbol min max min max min max min max unit conditions frt timer output t ftod 150 100 100 100 ns fig. 15-11 delay time timer input t ftis 80 50 50 50 ns fig. 15-11 setup time timer clock t ftcs 80 50 50 50 ns fig. 15-12 input setup time timer clock t ftcwh 1.5 1.5 1.5 1.5 t cyc fig. 15-12 pulse width t ftcwl 243
table 15-8. timing conditions of on-chip supporting modules (cont.) condition a: v cc = 5.0v 10%, = 0.5 to 10mhz, v ss = 0v, ta = ?0 to 75?c (regular specifications), ta = ?0 to 85?c (wide-range specifications) condition b: v cc = 2.7 to 3.6v, v ss = 0v, ta = ?0 to 75?c, for only h8/3257 and h8/3256 condition b condition a 5mhz 6mhz 8mhz 10mhz measurement item symbol min max min max min max min max unit conditions tmr timer output t tmod 150 100 100 100 ns fig. 15-13 delay time timer reset t tmrs 80 50 50 50 ns fig. 15-15 input setup time timer clock t tmcs 80 50 50 50 ns fig. 15-14 input setup time timer clock t tmcwh 1.5 1.5 1.5 1.5 t cyc fig. 15-14 pulse width (single edge) timer clock t tmcwl 2.5 2.5 2.5 2.5 t cyc fig. 15-14 pulse width (both edges) sci input (async) t scyc 2 2 2 2 t cyc fig. 15-16 clock (sync) t scyc 4 4 4 4 t cyc fig. 15-16 cycle transmit data t txd 200 100 100 100 ns fig. 15-16 delay time (sync) receive data t rxs 150 100 100 100 ns fig. 15-16 setup time (sync) receive data t rxh 150 100 100 100 ns fig. 15-16 hold time (sync) input clock t sckw 0.4 0.6 0.4 0.6 0.4 0.6 0.4 0.6 t scyc fig. 15-17 pulse width ports output data t pwd 150 100 100 100 ns fig. 15-18 delay time input data setup t prs 80 50 50 50 ns fig. 15-18 time input data hold t prh 80 50 50 50 ns fig. 15-18 time 244
table 15-8. timing conditions of on-chip supporting modules (cont.) condition a: v cc = 5.0v 10%, = 0.5 to 10mhz, v ss = 0v, ta = ?0 to 75?c (regular specifications), ta = ?0 to 85?c (wide-range specifications) condition b: v cc = 2.7 to 3.6v, v ss = 0v, ta = ?0 to 75?c, for only h8/3257 and h8/3256 condition b condition a 5mhz 6mhz 8mhz 10mhz measurement item symbol min max min max min max min max unit conditions parallel handshake t hisw 1.5 1.5 1.5 1.5 t cyc fig. 15-19 handshake input strobe interface pulse width handshake t his 10 10 10 10 ns fig. 15-19 input data setup time handshake t hih 120 120 120 120 ns fig. 15-19 input data hold time handshake t hosd1 100 80 80 80 ns fig. 15-20 output strobe t hosd2 100 80 80 80 ns fig. 15-20 delay time busy output t hbsod1 150 150 150 150 ns fig. 15-21 delay time t hbsod2 150 150 150 150 ns fig. 15-21 ? measurement conditions for ac characteristics figure 15-3. output load circuit fig. 15-3 5 v lsi output pin input/output timing reference levels low: high: 0.8 v 2.0 v 90 pf: ports 1, 2, 3, 4 6 , 6, 7 30 pf: ports 4 (except 4 6 ), 5 2.4 k 12 k c = r l = r h = c r l r h 245
15.3 mcu operational timing this section provides the following timing charts: 15.3.1 bus timing figures 15-4 to 15-6 15.3.2 control signal timing figures 15-7 to 15-10 15.3.3 16-bit free-running timer timing figures 15-11 to 15-12 15.3.4 8-bit timer timing figures 15-13 to 15-15 15.3.6 sci timing figures 15-15 to 15-17 15.3.7 i/o port timing figure 15-18 15.3.8 parallel handshaking interface timing figures 15-19 to 15-21 15.3.1 bus timing (1) basic bus cycle (without wait states) in expanded modes figure 15-4. basic bus cycle (without wait states) in expanded modes t t 1 t cyc 2 t 3 t ch t cl t ad t cr t asd t acc t rds t wsd t as2 t wdd t wds t wdh t ah t wsw t rdh t ah t sd a 15 to a 0 ios wr d 7 to d 0 (read) d 7 to d 0 (write) as, rd (read) t cf t asi t sd fig. 17-4 246
(2) basic bus cycle (with 1 wait state) in expanded modes figure 15-5. basic bus cycle (with 1 wait state) in expanded modes as, rd wr wait d 7 to d 0 (read) a 15 to a 0 ios d 7 to d 0 (write) t 1 t 2 t w t 3 t wts t wth t wts t wth 247
(3) e clock bus cycle figure 15-6. e clock bus cycle 15.3.2 control signal timing (1) reset input timing figure 15-7. reset input timing t ad t ed t e r t e f t ed t ah t sd t as1 t ad t rds t rdh t rdhe t wdhe e a 15 to a 0 , ios as rd, wr d 7 to d 0 (read) d 7 to d 0 (write) t ad fig. 15-6 md 1 and md 0 res t ress t mds t ress t resw 248
(2) interrupt input timing figure 15-8. interrupt input timing irq i (level) nmi irq i t t t nmi irq i (edge) nmis nmis nmih t nmiw note : i = 0 to 2 fig. 15-8 249
(3) clock settling timing v cc res stby t osc1 t osc1 figure 15-9. clock settling timing 250
(4) clock settling timing for recovery from software standby mode figure 15-10. clock settling timing for recovery from software standby mode 15.3.3 16-bit free-running timer timing (1) free-running timer input/output timing figure 15-11. free-running timer input/output timing osc2 nmi irq i (i = 0, 1, 2) t compare-match fti (without noise canceler) ftoa , ftob free-running timer counter t ftod t ftis fig. 15-11 251
(2) external clock input timing for free-running timer figure 15-12. external clock input timing for free-running timer 15.3.4 8-bit timer timing (1) 8-bit timer output timing figure 15-13. 8-bit timer output timing (2) 8-bit timer clock input timing figure 15-14. 8-bit timer clock input timing ftci t ftcs t ftcwl t ftcwh timer counter compare- match tmo 1 , tmo 0 t tmod fig. 15-13 t tmcs t tmcs t tmcwl t tmcwh tmci 0 , tmci 1 fig. 15-14 252
(3) 8-bit timer reset input timing figure 15-15. 8-bit timer reset input timing 15.3.5 serial communication interface timing (1) sci input/output timing figure 15-16. sci input/output timing (synchronous mode) (2) sci input clock timing figure 15-17. sci input clock timing n h'00 timer counter t tmrs tmri 0 , tmri 1 t scyc t txd t rxs t rxh serial clock sck sck transmit data txd txd receive data rxd rxd fig. 15-16 0 1 0 1 0 1 t sckw t scyc sck 1 sck 0 fig. 15-17 253
15.3.6 i/o port timing figure 15-18. i/o port input/output timing 15.3.7 parallel handshake interface timing (1) input strobe input timing figure 15-19. input strobe input timing * except p4 6 port read/write cycle t 1 t 2 t 3 t prs t prh t pwd port 1 to port 7 (input) port 1* to port 7 (output) fig. 15-18 p3 to p3 7 0 is fig. 15-19 t his t hih t hisw 254
(2) output strobe output timing figure 15-20. output strobe output timing (3) busy output timing figure 15-21. busy output timing fig. 15-20 os t hosd1 t hosd2 fig. 15-21 is busy t hbsod1 t hbsod2 255
appendix a. cpu instruction set a.1 instruction set list operation notation rd8/16 general register (destination) (8 or 16 bits) rs8/16 general register (source) (8 or 16 bits) rn8/16 general register (8 or 16 bits) ccr condition code register n n (negative) flag in ccr z z (zero) flag in ccr v v (overflow) flag in ccr c c (carry) flag in ccr pc program counter sp stack pointer #xx:3/8/16 immediate data (3, 8, or 16 bits) d:8/16 displacement (8 or 16 bits) @aa:8/16 absolute address (8 or 16 bits) + addition subtraction multiplication division and logical or logical ? exclusive or logical ? move not condition code notation modified according to the instruction result * undetermined (unpredictable) 0 always cleared to "0" not affected by the instruction result 257
a.2 operation code map table a-2 is a map of the operation codes contained in the first byte of the instruction code (bits 15 to 8 of the first instruction word). some pairs of instructions have identical first bytes. these instructions are differentiated by the first bit of the second byte (bit 7 of the first instruction word). instruction when first bit of byte 2 (bit 7 of first instruction word) is 0. instruction when first bit of byte 2 (bit 7 of first instruction word) is 1. 264
table a-2. operation code map * 1 the movfpe and movtpe instructions are identical to mov instructions in the first byte and first bit of the second byte (bits 15 to 7 of the instruction word). the push and pop instructions are identical in machine language to mov instructions. * 2 the bt, bf, bhs, and blo instructions are identical in machine language to bra, brn, bcc, and bcs, respectively. hi lo 0 1 2 3 4 5 6 7 8 9 a b c d e f 0 1 2 3 4 5 6 7 8 9 a b c d e f nop sleep stc ldc orc xorc andc ldc add inc adds mov addx daa shll shal shlr shar rotxl rotl rotxr rotr not neg or xor and sub dec subs cmp subx das mov bra brn bhi bls bcc bcs bne beq bvs bpl bmi blt bgt ble mulxu divxu rts bsr rte jmp jsr bvc bge bset bnot bclr btst mov mov eepmov add addx cmp subx or xor and mov bxor bixor band biand bor bior bld bild bst bist bit manipulation instruction *1 *2 *2 *2 *2 265
a.3 number of states required for execution the tables below can be used to calculate the number of states required for instruction execution. table a-3 indicates the number of states required for each cycle (instruction fetch, branch address read, stack operation, byte data access, word data access, internal operation). table a-4 indicates the number of cycles of each type occurring in each instruction. the total number of states required for execution of an instruction can be calculated from these two tables as follows: execution states = i s i + j s j + k s k + l s l + m s m + n s n examples: mode 1 (on-chip rom disabled), stack located in external memory, 1 wait state inserted in external memory access. 1. bset #0, @ffc7 from table a-4: i = l = 2, j = k = m = n= 0 from table a-3: s i = 8, s l = 3 number of states required for execution: 2 8 + 2 3 =22 2. jsr @@30 from table a-4: i = 2, j = k = 1, l = m = n = 0 from table a-3: s i = s j = s k = 8 number of states required for execution: 2 8 + 1 8 + 1 8 = 32 table a-3. number of states taken by each cycle in instruction execution notes: 1. m: number of wait states inserted in access to external device. 2. the byte data access cycle to an external device by the movfpe and movtpe instructions requires 9 to 16 states since it is synchronized with the e clock. see section 13, e-clock interface for timing details. execution status access location (instruction cycle) on-chip memory on-chip reg. field external memory instruction fetch s i branch address read s j 6 6 + 2m stack operation s k 2 byte data access s l 3 3 + m (note 2) word data access s m 6 6 + 2m internal operation s n 2 266
table a-4. number of cycles in each instruction instruction branch stack byte data word data internal fetch addr. read operation access access operation instruction mnemonic i j k l m n add add.b #xx:8, rd 1 add.b rs, rd 1 add.w rs, rd 1 adds adds.w #1/2, rd 1 addx addx.b #xx:8, rd 1 addx.b rs, rd 1 and and.b #xx:8, rd 1 and.b rs, rd 1 andc andc #xx:8, ccr 1 band band #xx:3, rd 1 band #xx:3, @rd 2 1 band #xx:3, @aa:8 2 1 bcc bra d:8 (bt d:8) 2 brn d:8 (bf d:8) 2 bhi d:8 2 bls d:8 2 bcc d:8 (bhs d:8) 2 bcs d:8 (blo d:8) 2 bne d:8 2 beq d:8 2 bvc d:8 2 bvs d:8 2 bpl d:8 2 bmi d:8 2 bge d:8 2 blt d:8 2 bgt d:8 2 ble d:8 2 bclr bclr #xx:3, rd 1 bclr #xx:3, @rd 2 2 bclr #xx:3, @aa:8 2 2 bclr rn, rd 1 bclr rn, @rd 2 2 bclr rn, @aa:8 2 2 note: blank entries are all zero. 267
table a-4. number of cycles in each instruction (cont.) instruction branch stack byte data word data internal fetch addr. read operation access access operation instruction mnemonic i j k l m n biand biand #xx:3, rd 1 biand #xx:3, @rd 2 1 biand #xx:3, @aa:8 2 1 bild bild #xx:3, rd 1 bild #xx:3, @rd 2 1 bild #xx:3, @aa:8 2 1 bior bior #xx:3 rd 1 bior #xx:3 @rd 2 1 bior #xx:3 @aa:8 2 1 bist bist #xx:3, rd 1 bist #xx:3, @rd 2 2 bist #xx:3, @aa:8 2 2 bixor bixor #xx:3, rd 1 bixor #xx:3, @rd 2 1 bixor #xx:3, @aa:8 2 1 bld bld #xx:3, rd 1 bld #xx:3, @rd 2 1 bld #xx:3, @aa:8 2 1 bnot bnot #xx:3, rd 1 bnot #xx:3, @rd 2 2 bnot #xx:3, @aa:8 2 2 bnot rn, rd 1 bnot rn, @rd 2 2 bnot rn, @aa:8 2 2 bor bor #xx:3, rd 1 bor #xx:3, @rd 2 1 bor #xx:3, @aa:8 2 1 bset bset #xx:3, rd 1 bset #xx:3, @rd 2 2 bset #xx:3, @aa:8 2 2 bset rn, rd 1 bset rn, @rd 2 2 bset rn, @aa:8 2 2 note: blank entries are all zero. 268
table a-4. number of cycles in each instruction (cont.) instruction branch stack byte data word data internal fetch addr. read operation access access operation instruction mnemonic i j k l m n bsr bsr d:8 2 1 bst bst #xx:3, rd 1 bst #xx:3, @rd 2 2 bst #xx:3, @aa:8 2 2 btst btst #xx:3, rd 1 btst #xx:3, @rd 2 1 btst #xx:3, @aa:8 2 1 btst rn, rd 1 btst rn, @rd 2 1 btst rn, @aa:8 2 1 bxor bxor #xx:3, rd 1 bxor #xx:3, @rd 2 1 bxor #xx:3, @aa:8 2 1 cmp cmp.b #xx:8, rd 1 cmp.b rs, rd 1 cmp.w rs, rd 1 daa daa.b rd 1 das das.b rd 1 dec dec.b rd 1 divxu divxu.b rs, rd 1 6 eepmov eepmov 2 2n+2 *1 inc inc.b rd 1 jmp jmp @rn 2 jmp @aa:16 2 1 jmp @@aa:8 2 1 1 jsr jsr @rn 2 1 jsr @aa:16 2 1 1 jsr @@aa:8 2 1 1 ldc ldc #xx:8, ccr 1 ldc rs, ccr 1 mov mov.b #xx:8, rd 1 mov.b rs, rd 1 mov.b @rs, rd 1 1 mov.b @(d:16,rs), rd 2 1 note: blank entries are all zero. 269
table a-4. number of cycles in each instruction (cont.) instruction branch stack byte data word data internal fetch addr. read operation access access operation instruction mnemonic i j k l m n mov mov.b @rs+, rd 1 1 1 mov.b @aa:8, rd 1 1 mov.b @aa:16, rd 2 1 mov.b rs, @rd 1 1 mov.b rs, @(d:16, rd) 2 1 mov.b rs, @?d 1 1 1 mov.b rs, @aa:8 1 1 mov.b rs, @aa:16 2 1 mov.w #xx:16, rd 2 mov.w rs, rd 1 mov.w @rs, rd 1 1 mov.w @(d:16, rs), rd 2 1 mov.w @rs+, rd 1 1 1 mov.w @aa:16, rd 2 1 mov.w rs, @rd 1 1 mov.w rs, @(d:16, rd) 2 1 mov.w rs, @?d 1 1 1 mov.w rs, @aa:16 2 1 movfpe movfpe @aa:16, rd 2 1 *2 movtpe movtpe. rs, @aa:16 2 1 *2 mulxu mulxu. rs, rd 1 6 neg neg.b rd 1 nop nop 1 not not.b rd 1 or or.b #xx:8, rd 1 or.b rs, rd 1 orc orc #xx:8, ccr 1 rotl rotl.b rd 1 rotr rotr.b rd 1 rotxl rotxl.b rd 1 rotxr rotxr.b rd 1 rte rte 2 2 1 rts rts 2 1 1 note: blank entries are all zero. 270
table a-4. number of cycles in each instruction (cont.) instruction branch stack byte data word data internal fetch addr. read operation access access operation instruction mnemonic i j k l m n shal shal.b rd 1 shar shar.b rd 1 shll shll.b rd 1 shlr shlr.b rd 1 sleep sleep 1 stc stc ccr , rd 1 sub sub.b rs, rd 1 sub.w rs, rd 1 subs subs.w #1/2, rd 1 subx subx.b #xx:8, rd 1 subx.b rs, rd 1 xor xor.b #xx:8, rd 1 xor.b rs, rd 1 xorc xorc #xx:8, ccr 1 notes: *1 n: initial value in r4l. source and destination are accessed n + 1 times each. *2 data access requires 9 to 16 states. blank entries are all zero. 271
appendix b. register field b.1 register addresses and bit names addr. (last register bit names byte) name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 module h'80 external h'81 addresses h'82 (in h'83 expanded h'84 modes) h'85 h'86 h'87 h'88 h'89 h'8a h'8b h'8c h'8d h'8e h'8f h'90 tcr icie ocieb ociea ovie oeb oea cks1 cks0 frt h'91 tcsr icf ocfb ocfa ovf olvlb olvla iedg cclra h'92 frc (h) h'93 frc (l) h'94 ocra (h) h'95 ocra (l) h'96 ocrb (h) h'97 ocrb (l) h'98 icr (h) h'99 icr (l) h'9a h'9b h'9c h'9d h'9e h'9f notes: frt: 16-bit free-running timer (continued on next page) 272
(continued from previous page) addr. (last register bit names byte) name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 module h'a0 external h'a1 addresses h'a2 (in h'a3 expanded h'a4 modes) h'a5 h'a6 h'a7 h'a8 h'a9 h'aa h'ab h'ac h'ad h'ae h'af h'b0 p1ddr p1 7 ddr p1 6 ddr p1 5 ddr p1 4 ddr p1 3 ddr p1 2 ddr p1 1 ddr p1 0 ddr port 1 h'b1 p2ddr p2 7 ddr p2 6 ddr p2 5 ddr p2 4 ddr p2 3 ddr p2 2 ddr p2 1 ddr p2 0 ddr port 2 h'b2 p1dr p1 7 p1 6 p1 5 p1 4 p1 3 p1 2 p1 1 p1 0 port 1 h'b3 p2dr p2 7 p2 6 p2 5 p2 4 p2 3 p2 2 p2 1 p2 0 port 2 h'b4 p3ddr p3 7 ddr p3 6 ddr p3 5 ddr p3 4 ddr p3 3 ddr p3 2 ddr p3 1 ddr p3 0 ddr port 3 h'b5 p4ddr p4 7 ddr p4 6 ddr p4 5 ddr p4 4 ddr p4 3 ddr p4 2 ddr p4 1 ddr p4 0 ddr port 4 h'b6 p3dr p3 7 p3 6 p3 5 p3 4 p3 3 p3 2 p3 1 p3 0 port 3 h'b7 p4dr p4 7 p4 6 p4 5 p4 4 p4 3 p4 2 p4 1 p4 0 port 4 h'b8 p5ddr p5 5 ddr p5 4 ddr p5 3 ddr p5 2 ddr p5 1 ddr p5 0 ddr port 5 h'b9 p6ddr p6 6 ddr p6 5 ddr p6 4 ddr p6 3 ddr p6 2 ddr p6 1 ddr p6 0 ddr port 6 h'ba p5dr p5 5 p5 4 p5 3 p5 2 p5 1 p5 0 port 5 h'bb p6dr p6 6 p6 5 p6 4 p6 3 p6 2 p6 1 p6 0 port 6 h'bc p7ddr p7 7 ddr p7 6 ddr p7 5 ddr p7 4 ddr p7 3 ddr p7 2 ddr p7 1 ddr p7 0 ddr port 7 h'bd h'be p7dr p7 7 p7 6 p7 5 p7 4 p7 3 p7 2 p7 1 p7 0 port 7 h'bf (continued on next page) 273
(continued from preceding page) addr. (last register bit names byte) name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 module h'c0 h'c1 h'c2 h'c3 h'c4 syscr ssby sts2 sts1 sts0 nmieg rame system h'c5 mdcr mds1 mds0 control h'c6 iscr irq 2 eg irq 1 eg irq 0 eg irq 2 sc irq 1 sc irq 0 sc h'c7 ier irq 2 e irq 1 e irq 0 e h'c8 tcr cmieb cmiea ovie cclr1 cclr0 cks2 cks1 cks0 tmr0 h'c9 tcsr cmfb cmfa ovf os3 os2 os1 os0 h'ca tcora h'cb tcorb h'cc tcnt h'cd h'ce h'cf h'd0 tcr cmieb cmiea ovie cclr1 cclr0 cks2 cks1 cks0 tmr1 h'd1 tcsr cmfb cmfa ovf os3 os2 os1 os0 h'd2 tcora h'd3 tcorb h'd4 tcnt h'd5 h'd6 h'd7 h'd8 smr c/a chr pe o/e stop cks1 cks0 sci0 h'd9 brr h'da scr tie rie te re cke1 cke0 h'db tdr h'dc ssr tdre rdrf orer fer per h'dd rdr h'de h'df (continued on next page) notes: tmr1: 8-bit timer channel 0 tmr1: 8-bit timer channel 1 sci0: serial communication interface channel 0 274
(continued from preceding page) addr. (last register bit names byte) name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 module h'e0 smr c/a chr pe o/e stop cks1 cks0 sci1 h'e1 brr h'e2 scr tie rie te re cke1 cke0 h'e3 tdr h'e4 ssr tdre rdrf orer fer per h'e5 rdr h'e6 h'e7 h'e8 h'e9 h'ea h'eb h'ec h'ed h'ee h'ef h'f0 h'f1 h'f2 h'f3 h'f4 h'f5 h'f6 h'f7 h'f8 h'f9 h'fa h'fb h'fc h'fd h'fe hcsr isf isie ose oss lte bse handshaking h'ff fncr ncs1 ncs0 frt note: sci1: serial communication interface channel 1 frt: 16-bit free-running timer 275
b.2 register descriptions 276
tcr?imer control register h?f90 frt bit 7 6 5 4 3 2 1 0 icie ocieb ociea ovie oeb oea cks1 cks0 initial value 0 0 0 0 0 0 0 0 read/write r/w r/w r/w r/w r/w r/w r/w r/w bits 1 and 0 ?clock select (cks1 and cks0) 0 0 /2 internal clock source 0 1 /8 internal clock source 1 0 /32 internal clock source 1 1 external clock source (rising edge) output enable a (oea) 0 output compare a output is disabled. 1 output compare a output is enabled. output enable b (oeb) 0 output compare b output is disabled. 1 output compare b output is enabled. timer overflow interrupt enable 0 timer overflow interrupt request is disabled. 1 timer overflow interrupt request is enabled. output compare interrupt a enable 0 output compare interrupt request a is disabled. 1 output compare interrupt request a is enabled. output compare interrupt b enable 0 output compare interrupt request b is disabled. 1 output compare interrupt request b is enabled. input capture interrupt enable 0 input capture interrupt request is disabled. 1 input capture interrupt request is enabled. 277
tcsr?imer control/status register h?f91 frt bit 7 6 5 4 3 2 1 0 icf ocfb ocfa ovf olvlb olvla iedg cclra initial value 0 0 0 0 0 0 0 0 read/write r/(w)* r/(w)* r/(w)* r/(w)* r/w r/w r/w r/w counter clear a 0 frc is not cleared. 1 frc is cleared at compare-match a. input edge select 0 falling edge of fti is valid. 1 rising edge of fti is valid. output level a 0 compare-match a causes 0 output. 1 compare-match a causes 1 output. output level b 0 compare-match b causes 0 output. 1 compare-match b causes 1 output. timer overflow flag 0 cleared by reading ovf = 1, then writing 0. 1 set when frc changes from h?fff to h?000. output compare flag a 0 cleared by reading ocfa = 1, then writing 0. 1 set when frc = ocra. output compare flag b 0 cleared by reading ocfb = 1, then writing 0. 1 set when frc = ocrb. input capture flag 0 cleared by reading icf = 1, then writing 0. 1 set when fti input causes frc to be copied to icr. * software can write a 0 in bits 7 to 4 to clear the flags, but cannot write a 1 in these bits. 278
frc (h and l)?ree-running counter h?f92, h?f93 frt bit 7 6 5 4 3 2 1 0 initial value 0 0 0 0 0 0 0 0 read/write r/w r/w r/w r/w r/w r/w r/w r/w count value ocra (h and l)?utput compare register a h?f94, h?f95 frt bit 7 6 5 4 3 2 1 0 initial value 1 1 1 1 1 1 1 1 read/write r/w r/w r/w r/w r/w r/w r/w r/w continually compared with frc. ocfa is set to 1 when ocra = frc. ocrb (h and l)?utput compare register b h?f96, h?f97 frt bit 7 6 5 4 3 2 1 0 initial value 1 1 1 1 1 1 1 1 read/write r/w r/w r/w r/w r/w r/w r/w r/w continually compared with frc. ocfb is set to 1 when ocrb = frc. icr (h and l)?nput capture register h?f98, h?f99 frt bit 7 6 5 4 3 2 1 0 initial value 0 0 0 0 0 0 0 0 read/write r r r r r r r r contains frc count captured on fti input. 279
p1ddr?ort 1 data direction register h?fb0 port 1 bit 7 6 5 4 3 2 1 0 p1 7 ddr p1 6 ddr p1 5 ddr p1 4 ddr p1 3 ddr p1 2 ddr p1 1 ddr p1 0 ddr mode 1 initial value 1 1 1 1 1 1 1 1 read/write modes 2 and 3 initial value 0 0 0 0 0 0 0 0 read/write w w w w w w w w port 1 input/output control 0 input port 1 output port p1dr?ort 1 data register h?fb2 port 1 bit 7 6 5 4 3 2 1 0 p1 7 p1 6 p1 5 p1 4 p1 3 p1 2 p1 1 p1 0 initial value 0 0 0 0 0 0 0 0 read/write r/w r/w r/w r/w r/w r/w r/w r/w p2ddr?ort 2 data direction register h?fb1 port 2 bit 7 6 5 4 3 2 1 0 p2 7 ddr p2 6 ddr p2 5 ddr p2 4 ddr p2 3 ddr p2 2 ddr p2 1 ddr p2 0 ddr mode 1 initial value 1 1 1 1 1 1 1 1 read/write modes 2 and 3 initial value 0 0 0 0 0 0 0 0 read/write w w w w w w w w port 2 input/output control 0 input port 1 output port 280
p2dr?ort 2 data register h?fb3 port 2 bit 7 6 5 4 3 2 1 0 p2 7 p2 6 p2 5 p2 4 p2 3 p2 2 p2 1 p2 0 initial value 0 0 0 0 0 0 0 0 read/write r/w r/w r/w r/w r/w r/w r/w r/w p3ddr?ort 3 data direction register h?fb4 port 3 bit 7 6 5 4 3 2 1 0 p3 7 ddr p3 6 ddr p3 5 ddr p3 4 ddr p3 3 ddr p3 2 ddr p3 1 ddr p3 0 ddr initial value 0 0 0 0 0 0 0 0 read/write w w w w w w w w port 3 input/output control 0 input port 1 output port p3dr?ort 3 data register h?fb6 port 3 bit 7 6 5 4 3 2 1 0 p3 7 p3 6 p3 5 p3 4 p3 3 p3 2 p3 1 p3 0 initial value 0 0 0 0 0 0 0 0 read/write r/w r/w r/w r/w r/w r/w r/w r/w 281
p4ddr?ort 4 data direction register h?fb5 port 4 bit 7 6 5 4 3 2 1 0 p4 7 ddr p4 6 ddr p4 5 ddr p4 4 ddr p4 3 ddr p4 2 ddr p4 1 ddr p4 0 ddr modes 1 and 2 initial value 1 0 0 0 0 0 0 0 read/write w w w w w w w w mode 3 initial value 0 0 0 0 0 0 0 0 read/write w w w w w w w w port 4 input/output control 0 input port 1 output port p4dr?ort 4 data register h?fb7 port 4 bit 7 6 5 4 3 2 1 0 p4 7 p4 6 p4 5 p4 4 p4 3 p4 2 p4 1 p4 0 initial value 0 0 0 0 0 0 0 0 read/write r/w r/w r/w r/w r/w r/w r/w r/w p5ddr?ort 5 data direction register h?fb8 port 5 bit 7 6 5 4 3 2 1 0 p5 5 ddr p5 4 ddr p5 3 ddr p5 2 ddr p5 1 ddr p5 0 ddr initial value 1 1 0 0 0 0 0 0 read/write w w w w w w port 5 input/output control 0 input port 1 output port 282
p5dr?ort 5 data register h?fba port 5 bit 7 6 5 4 3 2 1 0 p5 5 p5 4 p5 3 p5 2 p5 1 p5 0 initial value 1 1 0 0 0 0 0 0 read/write r/w r/w r/w r/w r/w r/w p6ddr?ort 6 data direction register h?fb9 port 6 bit 7 6 5 4 3 2 1 0 p6 6 ddr p6 5 ddr p6 4 ddr p6 3 ddr p6 2 ddr p6 1 ddr p6 0 ddr initial value 1 0 0 0 0 0 0 0 read/write w w w w w w w port 6 input/output control 0 input port 1 output port p6dr?ort 6 data register h?fbb port 6 bit 7 6 5 4 3 2 1 0 p6 6 p6 5 p6 4 p6 3 p6 2 p6 1 p6 0 initial value 1 0 0 0 0 0 0 0 read/write r/w r/w r/w r/w r/w r/w r/w p7ddr?ort 7 data direction register h?fbc port 7 bit 7 6 5 4 3 2 1 0 p7 7 ddr p7 6 ddr p7 5 ddr p7 4 ddr p7 3 ddr p7 2 ddr p7 1 ddr p7 0 ddr initial value 0 0 0 0 0 0 0 0 read/write w w w w w w w w port 7 input/output control 0 input port 1 output port 283
p7dr?ort 7 data register h?fbe port 7 bit 7 6 5 4 3 2 1 0 p7 7 p7 6 p7 5 p7 4 p7 3 p7 2 p7 1 p7 0 initial value 0 0 0 0 0 0 0 0 read/write r/w r/w r/w r/w r/w r/w r/w r/w syscr?ystem control register h?fc4 system control bit 7 6 5 4 3 2 1 0 ssby sts2 sts1 sts0 nmieg rame initial value 0 0 0 0 1 0 1 1 read/write r/w r/w r/w r/w r/w r/w ram enable 0 on-chip ram is disabled. 1 on-chip ram is enabled. nmi edge 0 falling edge of nmi is detected. 1 rising edge of nmi is detected. standby timer select 0 0 0 clock settling time = 8192 states 0 0 1 clock settling time = 16384 states 0 1 0 clock settling time = 32768 states 0 1 1 clock settling time = 65536 states 1 clock settling time = 131072 states software standby 0 sleep instruction causes transition to sleep mode. 1 sleep instruction causes transition to software standby mode. 284
mdcr?ode control register h?fc5 system control bit 7 6 5 4 3 2 1 0 mds1 mds0 initial value 1 1 1 0 0 1 * * read/write r r mode select value at mode pins. * determined by inputs at pins md 1 and md 0 . 285
iscr?rq sense control register h?fc6 system control bit 7 6 5 4 3 2 1 0 irq 2 eg irq 1 eg irq 0 eg irq 2 sc irq 1 sc irq 0 sc initial value 1 0 0 0 1 0 0 0 read/write r/w r/w r/w r/w r/w r/w r/w r/w irq 0 sense control, irq 0 edge irq 0 sc irq 0 eg description 0 0 low level of irq 0 generates an interrupt 0 1 request. 1 0 falling edge of irq 0 generates an interrupt request. 1 1 rising edge of irq 0 generates an interrupt request. irq 1 sense control, irq 1 edge irq 1 sc irq 1 eg description 0 0 low level of irq 1 generates an interrupt request. 0 1 1 0 falling edge of irq 1 generates an interrupt request. 1 1 rising edge of irq 1 generates an interrupt request. irq 2 sense control, irq 2 edge irq 2 sc irq 2 eg description 0 0 low level of irq 2 generates an interrupt request. 0 1 1 0 falling edge of irq 2 generates an interrupt request. 1 1 rising edge of irq 2 generates an interrupt request. 286
ier?rq enable register h?fc7 system control bit 7 6 5 4 3 2 1 0 irq 2 e irq 1 e irq 0 e initial value 1 1 1 1 1 0 0 0 read/write r/w r/w r/w irq i enable (i = 0 to 2) 0 irq i is disabled. 1 irq i is enabled. 287
tcr?imer control register h?fc8 tmr0 bit 7 6 5 4 3 2 1 0 cmieb cmiea ovie cclr1 cclr0 cks2 cks1 cks0 initial value 0 0 0 0 0 0 0 0 read/write r/w r/w r/w r/w r/w r/w r/w r/w clock select 0 0 0 no clock source; timer stops. 0 0 1 internal clock source: /8, counted on falling edge. 0 1 0 internal clock source: /64, counted on falling edge. 0 1 1 internal clock source: /1024, counted on falling edge. 1 0 0 no clock source; timer stops. 1 0 1 external clock source, counted on rising edge. 1 1 0 external clock source, counted on falling edge. 1 1 1 external clock source, counted on both rising and falling edges. counter clear 0 0 counter is not cleared. 0 1 cleared by compare-match a. 1 0 cleared by compare-match b. 1 1 cleared on rising edge of external reset input. timer overflow interrupt enable 0 overflow interrupt request is disabled. 1 overflow interrupt request is enabled. compare-match interrupt enable a 0 compare-match a interrupt request is disabled. 1 compare-match a interrupt request is enabled. compare-match interrupt enable b 0 compare-match b interrupt request is disabled. 1 compare-match b interrupt request is enabled. 288
tcsr?imer control/status register h?fc9 tmr0 bit 7 6 5 4 3 2 1 0 cmfb cmfa ovf os3 *2 os2 *2 os1 *2 os0 *2 initial value 0 0 0 1 0 0 0 0 read/write r/(w) *1 r/(w) *1 r/(w) *1 r/w r/w r/w r/w output select 0 0 no change on compare-match a. 0 1 output 0 on compare-match a. 1 0 output 1 on compare-match a. 1 1 invert (toggle) output on compare-match a. output select 0 0 no change on compare-match b. 0 1 output 0 on compare-match b. 1 0 output 1 on compare-match b. 1 1 invert (toggle) output on compare-match b. timer overflow flag 0 cleared by reading ovf = 1, then writing 0. 1 set when tcnt changes from h?f to h?0. compare-match flag a 0 cleared by reading cmfa = 1, then writing 0. 1 set when tcnt = tcora. compare-match flag b 0 cleared by reading cmfb = 1, then writing 0. 1 set when tcnt = tcorb. *1 software can write a 0 in bits 7 to 5 to clear the flags, but cannot write a 1 in these bits. *2 when all four bits (os3 to os0) are cleared to 0, output is disabled. 289
tcora?ime constant register a h?fca tmr0 bit 7 6 5 4 3 2 1 0 initial value 1 1 1 1 1 1 1 1 read/write r/w r/w r/w r/w r/w r/w r/w r/w the cmfa bit is set to 1 when tcora = tcnt. tcorb?ime constant register b h?fcb tmr0 bit 7 6 5 4 3 2 1 0 initial value 1 1 1 1 1 1 1 1 read/write r/w r/w r/w r/w r/w r/w r/w r/w the cmfb bit is set to 1 when tcorb = tcnt. tcnt?imer counter h?fcc tmr0 bit 7 6 5 4 3 2 1 0 initial value 0 0 0 0 0 0 0 0 read/write r/w r/w r/w r/w r/w r/w r/w r/w count value tcr?imer control register h?fd0 tmr1 bit 7 6 5 4 3 2 1 0 cmieb cmiea ovie cclr1 cclr0 cks2 cks1 cks0 initial value 0 0 0 0 0 0 0 0 read/write r/w r/w r/w r/w r/w r/w r/w r/w note: bit functions are the same as for tmr0. 290
tcsr?imer control/status register h?fd1 tmr1 bit 7 6 5 4 3 2 1 0 cmfb cmfa ovf os3 *2 os2 *2 os1 *2 os0 *2 initial value 0 0 0 1 0 0 0 0 read/write r/(w) *1 r/(w) *1 r/(w) *1 r/w r/w r/w r/w note: bit functions are the same as for tmr0. *1 software can write a 0 in bits 7 to 5 to clear the flags, but cannot write a 1 in these bits. *2 when all four bits (os3 to os0) are cleared to 0, output is disabled. tcora?ime constant register a h?fd2 tmr1 bit 7 6 5 4 3 2 1 0 initial value 1 1 1 1 1 1 1 1 read/write r/w r/w r/w r/w r/w r/w r/w r/w note: bit functions are the same as for tmr0. tcorb?ime constant register b h?fd3 tmr1 bit 7 6 5 4 3 2 1 0 initial value 1 1 1 1 1 1 1 1 read/write r/w r/w r/w r/w r/w r/w r/w r/w note: bit functions are the same as for tmr0. 291
tcnt?imer counter h?fd4 tmr1 bit 7 6 5 4 3 2 1 0 initial value 0 0 0 0 0 0 0 0 read/write r/w r/w r/w r/w r/w r/w r/w r/w note: bit functions are the same as for tmr0. 292
smr?erial mode register h?fd8 sci0 bit 7 6 5 4 3 2 1 0 c/a chr pe o/e stop cks1 cks0 initial value 0 0 0 0 0 1 0 0 read/write r/w r/w r/w r/w r/w r/w r/w clock select 0 0 clock 0 1 /4 clock 1 0 /16 clock 1 1 /64 clock stop bit length 0 one stop bit 1 two stop bits parity mode 0 even parity 1 odd parity parity enable 0 transmit: no parity bit added. receive: parity bit not checked. 1 transmit: parity bit added. receive: parity bit checked. character length 0 8-bit data length 1 7-bit data length communication mode 0 asynchronous 1 synchronous 293
tdr?ransmit data register h?fdb sci0 bit 7 6 5 4 3 2 1 0 initial value 1 1 1 1 1 1 1 1 read/write w w w w w w w w transmit data brr?it rate register h?fd9 sci0 bit 7 6 5 4 3 2 1 0 initial value 1 1 1 1 1 1 1 1 read/write r/w r/w r/w r/w r/w r/w r/w r/w constant that determines the bit rate 294
scr?erial control register h?fda sci0 bit 7 6 5 4 3 2 1 0 tie rie te re cke1 cke0 initial value 0 0 0 0 1 1 0 0 read/write r/w r/w r/w r/w r/w r/w clock enable 0 0 asynchronous serial clock not output at sck pin 1 asynchronous serial clock output at sck pin clock enable 1 0 internal clock 1 external clock receive enable 0 receive disabled 1 receive enabled transmit enable 0 transmit disabled 1 transmit enabled receive interrupt enable 0 receive interrupt request is disabled. 1 receive interrupt request is enabled. transmit interrupt enable 0 transmit interrupt request is disabled. 1 transmit interrupt request is enabled. 295
ssr?erial status register h?fdc sci0 bit 7 6 5 4 3 2 1 0 tdre rdrf orer fer per initial value 1 0 0 0 0 1 1 1 read/write r/(w)* r/(w)* r/(w)* r/(w)* r/(w)* parity error 0 cleared by reading per = 1, then writing 0. 1 set when a parity error occurs (parity of receive data does not match parity selected by o/e bit). framing error 0 cleared by reading fer = 1, then writing 0. 1 set when a framing error occurs (stop bit is 0). overrun error 0 cleared by reading orer = 1, then writing 0. 1 set when an overrun error occurs (reception of next data is completed while rdrf bit is set to 1). receive data register full 0 cleared by reading rdrf = 1, then writing 0. 1 set when one character is received normally and transferred from rsr to rdr. transmit data register empty 0 cleared by reading tdre = 1, then writing 0. 1 set when: 1. data is transferred from tdr to tsr. 2. te is cleared while tdre = 0. * software can write a 0 in bits 7 to 3 to clear the flags, but cannot write a 1 in these bits. 296
rdr?eceive data register h?fdd sci0 bit 7 6 5 4 3 2 1 0 initial value 0 0 0 0 0 0 0 0 read/write r r r r r r r r receive data smr?erial mode register h?fe0 sci1 bit 7 6 5 4 3 2 1 0 c/a chr pe o/e stop cks1 cks0 initial value 0 0 0 0 0 1 0 0 read/write r/w r/w r/w r/w r/w r/w r/w note: bit functions are the same as for sci0. brr?it rate register h?fe1 sci1 bit 7 6 5 4 3 2 1 0 initial value 1 1 1 1 1 1 1 1 read/write r/w r/w r/w r/w r/w r/w r/w r/w note: bit functions are the same as for sci0. scr?erial control register h?fe2 sci1 bit 7 6 5 4 3 2 1 0 tie rie te re cke1 cke0 initial value 0 0 0 0 1 1 0 0 read/write r/w r/w r/w r/w r/w r/w note: bit functions are the same as for sci0. 297
tdr?ransmit data register h?fe3 sci1 bit 7 6 5 4 3 2 1 0 initial value 1 1 1 1 1 1 1 1 read/write w w w w w w w w note: bit functions are the same as for sci0. ssr?erial status register h?fe4 sci1 bit 7 6 5 4 3 2 1 0 tdre rdrf orer fer per initial value 1 0 0 0 0 1 1 1 read/write r/(w)* r/(w)* r/(w)* r/(w)* r/(w)* note: bit functions are the same as for sci0. * software can write a 0 in bits 7 to 3 to clear the flags, but cannot write a 1 in these bits. rdr?eceive data register h?fe5 sci1 bit 7 6 5 4 3 2 1 0 initial value 0 0 0 0 0 0 0 0 read/write r r r r r r r r note: bit functions are the same as for sci0. 298
hcsr?andshake control/status register h?ffe handshaking bit 7 6 5 4 3 2 1 0 isf isie ose oss lte bse initial value 0 0 0 0 0 0 1 1 read/write r r/w r/w r/w r/w r/w busy enable 0 busy output is disabled. 1 busy output is enabled. latch enable 0 input latches are disabled. 1 input data are latched on falling edge of is. output strobe select 0 os is output when port 3 is read. 1 os is output when port 3 is written. output strobe enable 0 os output is disabled. 1 os output is enabled. input strobe interrupt enable 0 input strobe interrupt is disabled. 1 input strobe interrupt is enabled. interrupt strobe flag 0 cleared by reading hcsr when isf = 1, then reading or writing port 3. 1 set when is goes low. 299
fncr?rt noise canceler control register h?fff frt bit 7 6 5 4 3 2 1 0 ncs1 ncs0 initial value 1 1 1 1 1 1 0 0 read/write r/w r/w noise canceler select ncs1 ncs0 description 0 0 noise canceler is disabled. 0 1 /32 sampling clock 1 0 /64 sampling clock 1 1 /128 sampling clock 300
appendix c. pin states c.1 pin states in each mode table c-1. pin states pin mcu hardware software sleep normal name mode reset standby standby mode operation p1 7 to p1 0 1 low 3-state low prev. state addr. output a 7 to a 0 2 3-state low if (addr. addr. output ddr = 1, output pins: or input port prev. state last address if ddr = 0 accessed) 3 prev. state i/o port p2 7 to p2 0 1 low 3-state low prev. state addr. output a 15 to a 8 2 3-state low if (addr. addr. output ddr = 1, output pins: or input port prev. state last address if ddr = 0 accessed) 3 prev. state i/o port p3 7 to p3 0 1 3-state 3-state 3-state 3-state d 7 to d 0 d 7 to d 0 2 3 prev. state prev. state i/o port p4 7 /e 1 e clock 3-state low if e clock if e clock if 2 output ddr = 1, ddr = 1, ddr = 1, 3-state if 3-state if input port if ddr = 0 ddr = 0 ddr = 0 3 3-state prev. state prev. state i/o port p4 6 / 1 clock 3-state high clock clock 2 output output output 3 3-state high if clock output clock output ddr = 1, if ddr = 1, if ddr = 1, 3-state if 3-state if input port if ddr = 0 ddr = 0 ddr = 0 p4 5 to p4 0 , 1 3-state 3-state prev. state prev. state i/o port 2 (note 3) 3 301
table c-1. pin states (cont.) pin mcu hardware software sleep normal name mode reset standby standby mode operation p5 5 to p5 0 , 1 3-state 3-state prev. state prev. state i/o port 2 (note 3) 3 p6 6 to p6 0 , 1 3-state 3-state prev. state prev. state i/o port 2 (note 3) 3 p7 7 /wait 1 3-state 3-state 3-state 3-state wait 2 3 prev. state prev. state i/o port p7 6 to p7 4 , 1 high 3-state high high as, wr, as, wr, rd, 2 rd 3 3-state prev. state prev. state i/o port p7 3 to p7 0 , 1 3-state 3-state prev. state prev. state i/o port 2 3 notes: 1. 3-state: high-impedance state 2. prev. state: previous state. input ports are in the high-impedance state (with the mos pull-up on if ddr = 0 and dr = 1). output ports hold their previous output level. 3. on-chip supporting modules are initialized, so these pins revert to i/o ports according to the ddr and dr bits. 4. i/o port: direction depends on the data direction (ddr) bit. note that these pins may also be used by the on-chip supporting modules. see section 5, i/o ports for further information. 302
appendix d. timing of transition to and recovery from hardware standby mode timing of transition to hardware standby mode (1) to retain ram contents, drive the res signal low 10 system clock cycles before the stby signal goes low, as shown below. res must remain low until stby goes low (minimum delay from stby low to res high: 0 ns). (2) when it is not necessary to retain ram contents, res does not have to be driven low as in (1). timing of recovery from hardware standby mode: drive the res signal low approximately 100 ns before stby goes high. stby res t = 100 ns t osc stby res t 10 t 1 3 cyc t 0 ns 2 3 303
appendix e. package dimensions figure e-1 shows the dimensions of the dc-64s package. figure e-2 shows the dimensions of the dp-64s package. figure e-3 shows the dimensions of the fp-64a package. figure e-4 shows the dimensions of the cp-68 package. unit: mm figure e-1. package dimensions (dc-64s) unit: mm figure e-2. package dimensions (dp-64s) 0.25 + 0.11 ?0.05 0??15 1.78 ?0.25 0.48 ?0.10 0.51 min 2.54 min 5.08 max 19.05 57.6 58.50 max 1.0 1 33 32 64 17.0 18.6 max 0.48 ?0.10 + 0.11 ?0.05 57.30 18.92 0.9 64 33 1 32 1.778 ?0.250 0.25 19.05 5.60 max 2.54 min 0.51 min 304
unit: mm figure e-3. package dimensions (fp-64a) unit: mm figure e-4. package dimensions (cp-68) 0 ?5 0.1 0.15 m 17.2 ?0.3 48 33 49 64 1 16 32 17 17.2 0.3 0.35 ?0.10 0.80 3.05 max 0.1 1.6 0.8 ?0.3 14 2.70 +0.20 ?.16 0.17 +0.08 ?.05 1.27 0.42 ?0.10 24.20 23.12 0.50 23.12 ?0.50 4.40 ?0.20 2.55 ?0.15 0.10 25.15 ?0.12 25.15 ?0.12 60 61 68 1 9 10 44 26 43 27 0.75 305


▲Up To Search▲   

 
Price & Availability of H8-23

All Rights Reserved © IC-ON-LINE 2003 - 2022  

[Add Bookmark] [Contact Us] [Link exchange] [Privacy policy]
Mirror Sites :  [www.datasheet.hk]   [www.maxim4u.com]  [www.ic-on-line.cn] [www.ic-on-line.com] [www.ic-on-line.net] [www.alldatasheet.com.cn] [www.gdcy.com]  [www.gdcy.net]


 . . . . .
  We use cookies to deliver the best possible web experience and assist with our advertising efforts. By continuing to use this site, you consent to the use of cookies. For more information on cookies, please take a look at our Privacy Policy. X